SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    asp.net dropdownlist prob

    Hello guys, below my code always return value at index 0 for the dropdown list. not sure why.

    Code:
     try
                {
                    BindIndicator_default();
                    DropDownList ddlIndicator = (DropDownList)dataGridView.HeaderRow.FindControl("ddlIndicator");
                    string selectedValue = ddlIndicator.SelectedValue.ToString();
    
                    if (selectedValue != "" && selectedValue != "default")
                    {
                        BindIndicator(selectedValue);
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxShow(this, ex.Message.ToString());
                }
    This is the aspx part

    Code:
     <HeaderTemplate> Indicator<br /> 
                    <asp:DropDownList name="DDList" ID="ddlIndicator" runat="server" OnSelectedIndexChanged = "DropDownList1_SelectedIndexChanged" AutoPostBack = "true" AppendDataBoundItems = "true">
                        <asp:ListItem Text = "Default" Value = "default"></asp:ListItem>
                        <asp:ListItem Text = "First 10" Value = "WIP"></asp:ListItem>
                    </asp:DropDownList>
                    </HeaderTemplate>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You shouldn't need to work your way through the .NET controls in order to retrieve the selected option value, you should only need to use the following.

    Code Csharp:
    try
    {
        BindIndicator_default();
     
        // Get the selected option value
        string selectedValue = ddlIndicator.SelectedValue;
     
        if (!string.IsNullOrEmpty(selectedValue) && selectedValue != "default")
        {
            BindIndicator(selectedValue);
        }
    }
    catch (Exception ex)
    {
        MessageBoxShow(this, ex.Message.ToString());
    }


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •