We help IT Professionals succeed at work.
Get Started

get selected item from drop downlist

fwstealer
fwstealer asked
on
589 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.
Comment
Watch Question
Developer User Interface
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE