獲取DropDownList的SelectIndex的時候只能是0
來源:易賢網(wǎng) 閱讀:1600 次 日期:2014-08-04 15:32:59
溫馨提示:易賢網(wǎng)小編為您整理了“獲取DropDownList的SelectIndex的時候只能是0”,方便廣大網(wǎng)友查閱!

由于初始化判斷出錯導(dǎo)致每次傳到服務(wù)器的時候會初始化一次,這就導(dǎo)致每次獲取DropDownList的SelectIndex的時候只能是0

代碼如下:

<asp:DropDownList ID="ddlNameList" runat="Server" Height="30"

AutoPostBack="True" onselectedindexchanged="ddlNameList_SelectedIndexChanged" ></asp:DropDownList>

2.在服務(wù)端處理的時候,尤其是初始化DropDownList的時候,沒注意結(jié)果寫錯了,下面是錯誤代碼:

代碼如下:

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsCallBack)

{

this.fillIntoNameList();

}

}

這個初始化判斷出錯了,每次傳到服務(wù)器的時候會初始化一次,這就導(dǎo)致每次獲取DropDownList的SelectIndex的時候只能是0

正確代碼,如下:

代碼如下:

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

this.fillIntoNameList();

}

}

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:獲取DropDownList的SelectIndex的時候只能是0
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)