不知道是不是我逻辑的问题,我这是一个登录界面,可以再DropDownList里面选择身份是学生和管理员,我想实现当DropDownList选项是学生时,页面能够多两个label和新的DropDownList。但是页面运行时这两个label并没有出现。是把这两个label的初始Visible设为false。在 DropDownList1_SelectedIndexChanged里面写:
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "学生")
        {
            this.Label5.Visible = true;
            this.Label6.Visible = true;
            this.DropDownList2.Visible = true;
            this.DropDownList3.Visible = true;        }
    }
可是改变选项时,并没有出现应有的结果,是不是应该让页面刷新一下?重新刷新页面的代码是啥啊?

解决方案 »

  1.   

    你先在
    if (DropDownList1.SelectedValue == "学生")
    这行设置断点,运行,改变 DropDownList 选择,看看断点有没被中断,也就是事件有没被触发,如果触发再看选择“学生”时 DropDownList1.SelectedValue 的值是什么,是否满足 if 的条件。
      

  2.   

    果然,没有触发,压根就没有运行到断点这一步,为什么呢?改变DropDownList 的值不就应当执行DropDownList1_SelectedIndexChanged么?
      

  3.   

    我搜了下说要设置 DropDownList 属性 AutoPostBack 为 true 才会触发
    <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
    这个设置了吗?