国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

為什么設置了dropDownList的AutoPostBack=True還是不能觸發(fā)selected

2024-07-21 02:15:59
字體:
來源:轉載
供稿:網友

有人問
(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);
        }


怎么還是不能輸出選定項?進行調試發(fā)現(xiàn)不能進入selectedindexchanged事件。

其實還有一種可能,就是你為dropdownlist的不同option設置了相同的value

比如后臺這么寫:

if(!ispostback)
            {
                for(int i=0;i<10;i++)this.dropdownlist1.items.add(new listitem(i.tostring(),"same_value"));
            }


這樣不會觸發(fā)selectedindexchanged事件,修改成

if(!ispostback)
            {
                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)
            {
                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 事件
當列表控件的選定項在信息發(fā)往服務器之間變化時發(fā)生

這不同于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');");
            }

測試可知。

國內最大的酷站演示中心!
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 古浪县| 金昌市| 五莲县| 东安县| 临沭县| 罗平县| 阜康市| 西和县| 九龙城区| 靖边县| 三门县| 潞西市| 板桥市| 江源县| 忻州市| 镇巴县| 建始县| 耿马| 上蔡县| 法库县| 江达县| 隆回县| 滨海县| 平塘县| 河间市| 福海县| 隆子县| 高雄市| 锦屏县| 彭山县| 香港 | 蒙自县| 沾益县| 都兰县| 台湾省| 靖西县| 鹤岗市| 广州市| 翁牛特旗| 涿鹿县| 金乡县|