怎样在DropDownList控件中响应OnSelectedIndexChanged事件

来源:互联网 发布:风险矩阵分析法应用 编辑:程序博客网 时间:2024/06/05 07:38
出错情况:
1).aspx文件中:
<asp:DropDownList ID="SelectFirstSort"
runat="server"
OnSelectedIndexChanged="SelectFirstSort_Change">
</asp:DropDownList>
2).cs文件中:
protected void SelectFirstSort_Change(object sender, EventArgs e)
{
// if (SelectFirstSort.SelectedIndex == 1)
// {
SelectSecondSort.Items.Add("hehe");
// }
}

但是当第一个列表SelectFirstSort切换选项的时候,第二个列表SelectSecondSort没有去增加hehe文字。

解决方法:
在aspx文件中增加AutoPostBack="True"语句,这样就可以了。
<asp:DropDownList ID="SelectFirstSort"
runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="SelectFirstSort_Change">
</asp:DropDownList>

查询MSDN得知:
ListControl.AutoPostBack 属性含义:
获取或设置一个值,该值指示当用户更改列表中的选定内容时是否自动产生向服务器的回发。
0 0
原创粉丝点击