Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 21:14pm
v3
Comments
F-ES Sitecore 23-Oct-19 4:11am    
Does dropdownlist3 have autopostback enabled?

You probably need to use SelectedItem.Text, see example here: asp.net - SelectedValue vs SelectedItem.Value of DropDownList - Stack Overflow[^]
 
Share this answer
 
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;
      
}
 
Share this answer
 
Add update panel with child setup
 
Share this answer
 
put your dropdown list in this code

if (!IsPostBack)
            {
                do something

            }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900