在动态添加TextBox和Label之后,DropDownList控件';s SelectedIndexChang
本文关键字:控件 SelectedIndexChang DropDownList 添加 动态 TextBox 之后 Label | 更新日期: 2023-09-27 17:59:55
我有三个名为的DropdownList
- drp大学
- drp学院
- drp监督员
在我的页面中
在drpUniversity
中有一个大学列表,如果列出的大学对用户来说不够,则在最后一个索引中有"其他"。
类似于:
- 美国大学
- 乔治华盛顿大学
- 佛罗里达医院健康科学学院
- 和其他
现在,在drpUniversity_SelectedIndexChange
事件中,当用户选择Others(或最后一个索引)时,我添加了Label
和TextBox
。
我的代码:
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();
}
}
}
但是,问题是,当它创建TextBox
和Lable
时,其他名为drpFaculty的DropDownList
和drpSupersvisor的SelectedIndexChange
事件不起作用
在我的drpSupvisor SelectedIndexChange事件中有此代码:
protected void drpSupervisor_SelectedIndexChanged(object sender, EventArgs e)
{
txtSupervisorEmail.Text = drpSupervisor.SelectedItem.Value.ToString();
txtSupervisorEmail.Visible = true;
}
从drpUniversity选择其他人后,此操作不起作用
否则,这是有效的
请帮我解决这个问题
您的代码中似乎存在javascript错误。请检查broswer中的javascript错误控制台。