我已经创建了添加文本框的代码,但我不知道要删除添加的文本框。
分享我如何删除文本框;
counter ++;
TextBox tb = new TextBox();
tb.ID = "TextBox" +counter;
LiteralControl lineBreak = new LiteralControl();
PlaceHolder1.Controls.Add(tb); PlaceHolder1.Controls.Add(lineBreak);
controlIdList.Add(tb.ID);
ViewState["controlIdList"] = controlIdList;
答案 0 :(得分:0)
您可以从占位符中移除文本框,如下所示:
protected void Remove(object sender, EventArgs e)
{
foreach (Control control in PlaceHolder1.Controls)
{
//Here you need to take ID from ViewState["controlIdList"]
if (control.ID == "TakeIDFromControlListsID")
{
Controls.Remove(control);
}
}
}