1

I made a cascading dropdownlist.

This is the first ddl :

<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>

2nd ddl item is added based on item selected in ddl1 (OnSelectedIndexChanged)

3rd dll item is added based on item selected in ddl2 (OnSelectedIndexChanged)

I have a problem here which is when I use DropDownList3.SelectedItem.Text, it always return me the first item(CSGO or Dota based on each selection), ddl1 and ddl2 works fine for me.

Here is the ddl2 function :

   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", ""));
J.Boy
  • 15
  • 4

2 Answers2

0

I suspect that your problem is because you are disabling the first item, so it becomes not selectable.

Try without this line and see if your results are different.

DropDownList3.Items[0].Attributes["disabled"] = "disabled";
BizzyBob
  • 12,309
  • 4
  • 27
  • 51
  • I remove it but it still same, I can select any item inside, but the problem is when i click on submit button to submit the data into database, the data always is the first item – J.Boy Oct 22 '19 at 04:08
0

I successfully done it by using selecteditem.value which I assign value to it and it get it work, I wonder why selecteditem.text does not work.

J.Boy
  • 15
  • 4