DropDownList获取的SelectIndex一直为0

时间:2014-06-29 07:40:17   收藏:0   阅读:233

1.想要DropDownList自动提交必须设置AutoPostBack="true"属性,下面是代码:

<asp:DropDownList ID="ddlNameList" runat="Server" Height="30" 
            AutoPostBack="True" onselectedindexchanged="ddlNameList_SelectedIndexChanged" ></asp:DropDownList>


2.在服务端处理的时候,尤其是初始化DropDownList的时候,没注意结果写错了,下面是错误代码:

bubuko.com,布布扣
protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsCallBack)
        {
            this.fillIntoNameList();
        }
    }
bubuko.com,布布扣

 这个初始化判断出错了,每次传到服务器的时候会初始化一次,这就导致每次获取DropDownList的SelectIndex的时候只能是0

正确代码,如下:

bubuko.com,布布扣
protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
            this.fillIntoNameList();
        }
    }
bubuko.com,布布扣

 

 

DropDownList获取的SelectIndex一直为0,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!