有人問 
(1)autopostback="true" 
 <asp:dropdownlist id="dropdownlist1" runat="server" autopostback="true"></asp:dropdownlist>
<asp:dropdownlist id="dropdownlist1" runat="server" autopostback="true"></asp:dropdownlist> (2)事件也注冊了
 this.dropdownlist1.selectedindexchanged += new system.eventhandler(this.dropdownlist1_selectedindexchanged);
this.dropdownlist1.selectedindexchanged += new system.eventhandler(this.dropdownlist1_selectedindexchanged);  (3)事件也寫了  
  
 private void dropdownlist1_selectedindexchanged(object sender, system.eventargs e)
private void dropdownlist1_selectedindexchanged(object sender, system.eventargs e) 
 
         {
{  response.write(this.dropdownlist1.selecteditem);
            response.write(this.dropdownlist1.selecteditem);  }
        } 
怎么還是不能輸出選定項?進行調試發(fā)現(xiàn)不能進入selectedindexchanged事件。 
其實還有一種可能,就是你為dropdownlist的不同option設置了相同的value 
比如后臺這么寫: 
 if(!ispostback)
if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));  }
            } 
這樣不會觸發(fā)selectedindexchanged事件,修改成 
 if(!ispostback)
if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),i.tostring()));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),i.tostring()));  }
            } 
一切些正常,根據msdn的解釋: 
listcontrol.selectedindexchanged 事件 
當列表控件的選定項在信息發(fā)往服務器之間變化時發(fā)生 
這不同于js的onchange事件,改為 
 if(!ispostback)
    if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));  this.dropdownlist1.attributes.add("onchange","alert('test');");
                this.dropdownlist1.attributes.add("onchange","alert('test');");  }
            } 測試可知。
 if(!ispostback)
    if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));  this.dropdownlist1.attributes.add("onchange","alert('test');");
                this.dropdownlist1.attributes.add("onchange","alert('test');");  }
            } 測試可知。
 if(!ispostback)
if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),i.tostring()));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),i.tostring()));  }
            } 
一切些正常,根據msdn的解釋: 
listcontrol.selectedindexchanged 事件 
當列表控件的選定項在信息發(fā)往服務器之間變化時發(fā)生 
這不同于js的onchange事件,改為 
 if(!ispostback)
    if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));  this.dropdownlist1.attributes.add("onchange","alert('test');");
                this.dropdownlist1.attributes.add("onchange","alert('test');");  }
            } 測試可知。
 if(!ispostback)
    if(!ispostback) 
 
             {
{  for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));  this.dropdownlist1.attributes.add("onchange","alert('test');");
                this.dropdownlist1.attributes.add("onchange","alert('test');");  }
            } 測試可知。
國內最大的酷站演示中心!新聞熱點
疑難解答