1.想要DropDownList自動(dòng)提交必須設(shè)置AutoPostBack="true"屬性,下面是代碼:
<asp:DropDownList ID="ddlNameList" runat="Server" Height="30" AutoPostBack="True" onselectedindexchanged="ddlNameList_SelectedIndexChanged" ></asp:DropDownList>
2.在服務(wù)端處理的時(shí)候,尤其是初始化DropDownList的時(shí)候,沒注意結(jié)果寫錯(cuò)了,下面是錯(cuò)誤代碼:
PRotected void Page_Load(object sender, EventArgs e) { if (!Page.IsCallBack) { this.fillIntoNameList(); } }
這個(gè)初始化判斷出錯(cuò)了,每次傳到服務(wù)器的時(shí)候會(huì)初始化一次,這就導(dǎo)致每次獲取DropDownList的SelectIndex的時(shí)候只能是0
正確代碼,如下:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.fillIntoNameList(); } }新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注