I am trying to implement a simple filter from one dropdown box to another.
The second dropdown box deos not populate (with any item) when I select an item from the first dropdown.
I am not sure what I am missing.
Please advise.
Here is the ascx code:
<div id="SubmitSection" style="width:auto; height:auto;" class="SubmitSectionStyle">
<div id="DropdownSection" style="text-align:center;">
<asp:DropDownList ID="DropDown1" runat="server" AppendDataBoundItems="true"
onselectedindexchanged="Type_SelectedIndexChanged" ToolTip="Select Category">
<asp:ListItem Text="--Select Category--" Value="" />
<asp:ListItem Value="1">Department</asp:ListItem>
<asp:ListItem Value="2">Safety</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDown2" runat="server">
<asp:ListItem Text="--Select One--" Value="" />
</asp:DropDownList>
</div>
And here is my code behind:
protected void Type_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDown1.SelectedValue == "1")
{
DropDown2.Items.Clear();
DropDown2.Items.Add("DeptTest");
DropDown2.DataBind();
}
else if (DropDown1.SelectedValue == "2")
{
DropDown2.Items.Clear();
DropDown2.Items.Add("SafetyTest");
DropDown2.DataBind();
}
}
In your first dropdownlist, set AutoPostBack=”True”