DropDownList获取的SelectIndex一直为0的问题
<asp:DropDownListID="ddlNameList"runat="Server"Height="30" AutoPostBack="True"onselectedindexchanged="ddlNameList_SelectedIndexChanged"></asp:DropDownList>
2.在服务端处理的时候,尤其是初始化DropDownList的时候,没注意结果写错了,下面是错误代码:
protectedvoidPage_Load(objectsender,EventArgse) { if(!Page.IsCallBack) { this.fillIntoNameList(); } }
这个初始化判断出错了,每次传到服务器的时候会初始化一次,这就导致每次获取DropDownList的SelectIndex的时候只能是0
正确代码,如下:
protectedvoidPage_Load(objectsender,EventArgse) { if(!Page.IsPostBack) { this.fillIntoNameList(); } }