2006-07-15
分类:未分类
阅读(770) 评论(0)

有人问
(1)autopostback=”true”
<asp:dropdownlist id=”dropdownlist1″ runat=”server” autopostback=”true”></asp:dropdownlist>
(2)事件也注册了
this.dropdownlist1.selectedindexchanged += new system.eventhandler(this.dropdownlist1_selectedindexchanged);
(3)事件也写了
private void dropdownlist1_selectedindexchanged(object sender, system.eventargs e)

{
response.write(this.dropdownlist1.selecteditem);
}
怎么还是不能输出选定项?进行调试发现不能进入selectedindexchanged事件。
其实还有一种可能,就是你为dropdownlist的不同option设置了相同的value
比如后台这么写:
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),“same_value“));
}
这样不会触发selectedindexchanged事件,修改成
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),i.tostring()));
}
一切些正常,根据msdn的解释:
listcontrol.selectedindexchanged 事件
当列表控件的选定项在信息发往服务器之间变化时发生
这不同于js的onchange事件,改为
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),“same_value“));
this.dropdownlist1.attributes.add(“onchange“,“alert(test);“);
}
测试可知。
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),“same_value“));
this.dropdownlist1.attributes.add(“onchange“,“alert(test);“);
}
测试可知。
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),i.tostring()));
}
一切些正常,根据msdn的解释:
listcontrol.selectedindexchanged 事件
当列表控件的选定项在信息发往服务器之间变化时发生
这不同于js的onchange事件,改为
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),“same_value“));
this.dropdownlist1.attributes.add(“onchange“,“alert(test);“);
}
测试可知。
if(!ispostback)

{
for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),“same_value“));
this.dropdownlist1.attributes.add(“onchange“,“alert(test);“);
}
测试可知。

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:
IDC资讯中心 »
(论坛答疑点滴)为什么设置了DropDownList的AutoPostBack=True还是不能触发SelectedIndexChanged事件?-.NET教程,Asp.Net开发