我在ASP.NET Web窗体中创建了一些动态TextBox。请有人告诉我,如何获取相应文本框的文本值并将其保存到数据库中。这是我的代码:
for (int i = 0; i < n; i++)
{
MyTextBox.ID = "tb" + "" + ViewState["num"] + i;
this.PlaceHolder1.Controls.Add(MyTextBox);
}
答案 0 :(得分:0)
您使用FindControl:
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < n; i++)
{
TextBox tb = FindControl("tb" + ViewState["num"] + i) as TextBox;
string value = tb.Text;
}
}