在动态添加TextBox和Label之后,DropDownList控件的SelectedIndexChanged事件无法正常工作

时间:2013-02-18 05:51:02

标签: c# asp.net dynamic-controls

我有三个DropdownList名为

  1. drpUniversity
  2. drpFaculty
  3. drpSupervisor
  4. 在我的页面中。
    drpUniversity中有一个大学列表,如果列出的大学对用户不够,则在最后一个索引中有其他索引。
    如同:

    1. 美国大学,
    2. 乔治华盛顿大学,
    3. 佛罗里达医院健康科学学院
    4. 和其他人
    5. 现在,在drpUniversity_SelectedIndexChange事件中,当用户选择其他人(或最后一个索引)时,我添加了LabelTextBox

      我的代码:

       protected void drpUniversity_SelectedIndexChanged(object sender, EventArgs e)
       {
              if (IsPostBack)
              {
                  if (drpUniversity.SelectedItem.Value.ToString() == "Others".ToString())
                  {
                      int rowcount = mytable.Rows.Count;
                      HtmlTableRow row = new HtmlTableRow();
                      row.ID = "tbl_row" + (rowcount + 1);
                      HtmlTableCell cell1 = new HtmlTableCell();
                      cell1.ID = "tbl_cell1" + (rowcount + 1);
                      HtmlTableCell cell2 = new HtmlTableCell();
                      cell2.ID = "tbl_cell2" + (rowcount + 1);
                      cell1.Attributes["class"] = "contact";
                      cell2.Attributes["class"] = "contact";
                      TextBox tb = new TextBox();
                      tb.ID = "tbQty" + (rowcount + 1);
                      tb.Width = 276;
                      Label lblotherUniver = new Label();
                      lblotherUniver.ID = "lbluniversity";
                      lblotherUniver.Text = "University Name";
                      cell2.Controls.Add(lblotherUniver);
                      cell1.Controls.Add(tb);
                      row.Cells.Add(cell2);
                      row.Cells.Add(cell1);
                      mytable.Rows.Insert(8, row);
                      mytable.DataBind();
                  }
              }
        }
      

      但问题是,当它创建TextBoxLable时,其他DropDownList名为drpFaculty和drpSupervisor的SelectedIndexChange事件无效。< br />
      在我的drpSupervisor SelectedIndexChange事件中有此代码:

      protected void drpSupervisor_SelectedIndexChanged(object sender, EventArgs e)
      {
           txtSupervisorEmail.Text = drpSupervisor.SelectedItem.Value.ToString();
           txtSupervisorEmail.Visible = true;
      }
      

      在drpUniversity选择其他人之后这不起作用。
      否则这是有效的。
      请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

您的代码中似乎存在javascript错误。请检查broswer中的javascript错误控制台。