1.想要DropDownList自動提交必須設置AutoPostBack="true"屬性,下面是代碼:
復制代碼 代碼如下:
asp:DropDownList ID="ddlNameList" runat="Server" Height="30"
AutoPostBack="True" onselectedindexchanged="ddlNameList_SelectedIndexChanged" >/asp:DropDownList>
2.在服務端處理的時候,尤其是初始化DropDownList的時候,沒注意結果寫錯了,下面是錯誤代碼:
復制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallBack)
{
this.fillIntoNameList();
}
}
這個初始化判斷出錯了,每次傳到服務器的時候會初始化一次,這就導致每次獲取DropDownList的SelectIndex的時候只能是0
正確代碼,如下:
復制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.fillIntoNameList();
}
}
您可能感興趣的文章:- 基于Jquery的將DropDownlist的選中值賦給label的實現代碼
- 深入DropDownList用法的一些學習總結分析
- ASP.NET DropDownListCheckBox使用示例(解決回發(fā)問題)
- DropDownList綁定數據表實現兩級聯(lián)動示例
- ASP.NET MVC中為DropDownListFor設置選中項的方法
- JS簡單操作select和dropdownlist實例
- C#動態(tài)生成DropDownList執(zhí)行失敗原因分析
- DropDownList設置客戶端事件思路
- 解決DropDownList總是選中第一項的方法