Click here to Skip to main content
14,447,320 members
Rate this:
Please Sign up or sign in to vote.
When I want to get the data which the user selected in the third ddl, it always return me the first item.

When user select Game from ddl1 and B from ddl2, the ddl3 will populate the option, but ddl3.selecteditem.text will always return me Dota although the user select LoL as their option.

Is that anyway I can solve this issue? Any suggestion will be a great help. Thanks !

What I have tried:

Here is the ddl1 :
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack ="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="-- Select One --"></asp:ListItem>
<asp:ListItem Text="Game"></asp:ListItem>
<asp:ListItem Text="Book"></asp:ListItem>


Here is the function for ddl3:
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
   {
       DropDownList3.Visible = true;
       if (DropDownList2.SelectedValue == "A")
       {
           DropDownList3.Items.Clear();
           DropDownList3.Items.Insert(0, new ListItem("-Select-", "N"));
           DropDownList3.Items.Insert(1, new ListItem("CSGO", ""));
           DropDownList3.Items.Insert(2, new ListItem("CSO", ""));
           DropDownList3.Items[0].Attributes["disabled"] = "disabled";
       }
       else if (DropDownList2.SelectedValue == "B")
       {
           DropDownList3.Items.Clear();
           DropDownList3.Items.Insert(0, new ListItem("-Select-", "N"));
           DropDownList3.Items.Insert(1, new ListItem("Dota", ""));
           DropDownList3.Items.Insert(2, new ListItem("LoL", ""));
Posted
Updated 23-Oct-19 22:14pm
v3
Comments
F-ES Sitecore 23-Oct-19 4:11am
   
Does dropdownlist3 have autopostback enabled?
Rate this:
Please Sign up or sign in to vote.

Solution 1

You probably need to use SelectedItem.Text, see example here: asp.net - SelectedValue vs SelectedItem.Value of DropDownList - Stack Overflow[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

This problem could be caused because of ViewState() property of either page or control, please check if webforms ViewState() is disable or control's ViewState() could be disabled , if any of these ViewState Propperty is disabled, this problem could occur, so please enable ViewState of both Page and control, it can solve your issue.

void Page_Load(object sender, System.EventArgs e)
{
      DataBind();
      // Set EnableViewState to false to disable saving of view state 
      // information.
      myControl.EnableViewState = false;
      if (!IsPostBack)
         display.Enabled = false;
      
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Add update panel with child setup
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

put your dropdown list in this code

if (!IsPostBack)
            {
                do something

            }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100