[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

get selected item from drop downlist

Posted on 2012-08-16
2
Medium Priority
?
567 Views
Last Modified: 2012-08-16
i'm not sure why i can't get the selected item from my dropdownlist.

<asp:Label ID="lblWorkSheet" runat="server" Text="Select WorkSheet"></asp:Label>
<asp:DropDownList ID="ddlWorkSheets" runat="server" 
                onselectedindexchanged="ddlWorkSheets_SelectedIndexChanged">
            </asp:DropDownList>


protected void getFile()
        {
            string importPL = string.Empty;

            if (FileUpload1.HasFile)
            {
                string fileName = Server.HtmlEncode(FileUpload1.FileName); //name.xls
                string extension = System.IO.Path.GetExtension(fileName); //.xls xlsx
                string tableName = "PL";

                if ((extension == ".xls" || extension == ".xlsx"))
                {
                    FileInfo fileInfo = new FileInfo(FileUpload1.PostedFile.FileName);
                    SpreadSheet = FileUpload1.PostedFile.FileName;   //fileInfo.Name.ToString();
                    lblSpreadSheet.Text = "SpreadSheet: " + SpreadSheet.ToString(); //fileInfo.Name.ToString();

                    if (SpreadSheet.Trim() != string.Empty)
                    {
try
 {
 ArrayList strTables = GetTableExcel(SpreadSheet);
                            ddlWorkSheets.DataSource = strTables;
                            ddlWorkSheets.DataBind();

                            ListItem itm = new ListItem();
                            itm.Text = "";
                            itm.Value = "-1";
                            itm.Selected = true;
                            ddlWorkSheets.Items.Insert(0, itm);
                            ddlWorkSheets.SelectedIndex = 0;
 }
catch (Exception ex)
                        {
                            lblMessage.Text = ex.Message.ToString();
                        }

                    }
                }
            }

        }


protected void ddlWorkSheets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlWorkSheets.SelectedValue == "-1")
            {
                ddlWorkSheets.Focus();
            }
            else
            {
                lblWorkSheet.Text = "Worksheet: " + ddlWorkSheets.SelectedItem.ToString();
            }
        }

Open in new window


i just don't get it.
0
Comment
Question by:fwstealer
2 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 2000 total points
ID: 38302432
Are you checking the

if(!isPostBack) property before binding the dropdownlist?
0
 

Author Comment

by:fwstealer
ID: 38302459
duh - set autopostback to true


<asp:DropDownList ID="ddlWorkSheets" runat="server" AutoPostBack="True" onselectedindexchanged="ddlWorkSheets_SelectedIndexChanged">
            </asp:DropDownList>

protected void ddlWorkSheets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlWorkSheets.SelectedValue == "-1")
            {
                ddlWorkSheets.Focus();
            }
            else
            {
                lblWorkSheet.Text = "Worksheet: " + ddlWorkSheets.SelectedItem.ToString();

            }
        }

Open in new window


nothing happens
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question