日期:2014-02-06  浏览次数:20559 次

有人问
(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)