相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种:
1、DropDownList 控件的属性 AutoPostBack="True" 没有写;
2、DropDownList 控件的数据绑定没有放在if (!Page.IsPostBack) 里面;
3、DropDownList 控件选定项的value 值只有在发生变化时,才将信息发往服务器;
有人问
(1)AutoPostBack="True"
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
(2)事件也注册了
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
(3)事件也写了
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
怎么还是不能输出选定项?进行调试发现不能进入SelectedIndexChanged事件。
其实还有一种可能,就是你为DropDownList的不同option设置了相同的value
比如后台这么写:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
这样不会触发SelectedIndexChanged事件,修改成
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
一切些正常,根据msdn的解释:
ListControl.SelectedIndexChanged 事件
当列表控件的选定项在信息发往服务器之间变化时发生
这不同于js的onchange事件,改为
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
测试可知。