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", ""));