我有下拉列表它的事件(不显示你好)不起作用....
aspx页面
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
aspx.cs页面
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine("Hello");
}
问题是如果我在console.writeline中保持断点它不起作用......我在哪里犯了错误...任何想法。谢谢......
答案 0 :(得分:1)
在您的aspx代码中添加AutoPostBack="true"
,如下所示:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
答案 1 :(得分:1)
//添加AutoPostBack。
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" >
答案 2 :(得分:1)
除了一件事,一切都是正确的。只有在此状态为真时才会触发该事件
设置
AutoPostBack = "true"
//Actual code
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">