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

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
猜你喜欢
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2021-09-20
  • 2021-07-10
  • 2021-11-30
相关资源
相似解决方案