【发布时间】:2017-01-24 03:12:30
【问题描述】:
让我先说这是我努力学习更多 C#/.net 和 Web 开发的努力。所以这可能是显而易见的,但我没有看到它。
我正在尝试创建一个级联 DropDownList。我看过几个例子,但它们似乎都在查询数据库以获取它们的条目。我的要简单得多。根据第一个下拉列表的值,我将手动填充第二个。但是,我似乎没有让 OnSelectedIndexChange 触发。至少,DropDownList1_SelectedIndexChanged 似乎没有被执行。
这是 HTML:
<asp:ScriptManager ID="ScriptManager2" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" style="z-index: 1; margin-top: 40px; width: 150px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList><br/>
<asp:DropDownList ID="DropDownList2" runat="server" style="z-index: 1; margin-top: 10px; width: 150px">
</asp:DropDownList><br/>
</ContentTemplate>
</asp:UpdatePanel>
这里是 C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox2.Text = "Changed";
DropDownList1.Items.Clear();
switch (DropDownList1.Text)
{
case "Caesar Tools":
DropDownList2.Items.Add("Caesar Bruteforce");
DropDownList2.Items.Add("ROT-1");
DropDownList2.Items.Add("ROT-2");
DropDownList2.SelectedIndex = 1;
break;
case "ASCII Tools":
DropDownList2.Items.Add("Decimal to ASCII");
DropDownList2.Items.Add("Hex to ASCII");
DropDownList2.Items.Add("Binary to ASCII");
DropDownList2.SelectedIndex = 0;
break;
default:
break;
}
}
我错过了什么?
谢谢!
【问题讨论】:
-
这个msdn.microsoft.com/en-us/library/… 说“确保为列表控件启用了视图状态。” - 是吗?