DropDownList获取的SelectIndex一直为0的问题
更新时间:2014年06月05日 16:33:31 作者:
由于初始化判断出错导致每次传到服务器的时候会初始化一次,这就导致每次获取DropDownList的SelectIndex的时候只能是0
1.想要DropDownList自动提交必须设置AutoPostBack="true"属性,下面是代码:
<asp:DropDownList ID="ddlNameList" runat="Server" Height="30"
AutoPostBack="True" onselectedindexchanged="ddlNameList_SelectedIndexChanged" ></asp:DropDownList>
2.在服务端处理的时候,尤其是初始化DropDownList的时候,没注意结果写错了,下面是错误代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallBack)
{
this.fillIntoNameList();
}
}
这个初始化判断出错了,每次传到服务器的时候会初始化一次,这就导致每次获取DropDownList的SelectIndex的时候只能是0
正确代码,如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.fillIntoNameList();
}
}
复制代码 代码如下:
<asp:DropDownList ID="ddlNameList" runat="Server" Height="30"
AutoPostBack="True" onselectedindexchanged="ddlNameList_SelectedIndexChanged" ></asp:DropDownList>
2.在服务端处理的时候,尤其是初始化DropDownList的时候,没注意结果写错了,下面是错误代码:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallBack)
{
this.fillIntoNameList();
}
}
这个初始化判断出错了,每次传到服务器的时候会初始化一次,这就导致每次获取DropDownList的SelectIndex的时候只能是0
正确代码,如下:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.fillIntoNameList();
}
}
相关文章
ASP.NET Core 9.0 中新增的MapStaticAssets() 中
文章介绍了ASP.NET Core 9.0新增的MapStaticAssets中间件,该中间件解决了UseStaticFiles存在的缺陷,如缺乏静态资源传输压缩、ETag低效缓存和缺乏指纹识别,它通过生成时间压缩、基于内容的ETags和指纹识别来提升性能,感兴趣的朋友一起看看吧2024-12-12
Could not load file or assembly "App_Licenses.dll"
Could not load file or assembly "App_Licenses.dll"的问题2010-03-03
ASP.NET MVC通过勾选checkbox更改select的内容
这篇文章介绍了ASP.NET MVC通过勾选checkbox更改select内容的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-09-09


最新评论