我正在尝试实现一个从一个下拉框到另一个下拉框的简单过滤器。
当我从第一个下拉列表中选择一个项目时,第二个下拉框不会填充(包含任何项目)。我不确定我错过了什么。请指教。
这是ascx代码:
<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>
这是我背后的代码:
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();
}
}