for (j = 0; j ds.Tables[0].Rows.Count; j++)//ds为Dataset的对象,
{
string strname1 = ds.Tables[0].Rows[j][0].ToString();
HtmlGenericControl div = new HtmlGenericControl("div");
div.Style.Add("width", "100px");
div.Style.Add("height", "40px");
Label lab = new Label();
TextBox txt = new TextBox();
txt.ID = "txt_object" + j.ToString();
lab.Text = strname1 + ":";
txt.Width = Unit.Pixel(50);
div.Controls.Add(lab);
div.Controls.Add(txt);
this.Page.Form.Controls.Add(div);
}
得到文本框里面得值
(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/) protected void Button1_Click(object sender, EventArgs e)
{
int i = 1;//假定i为1
objText = ((TextBox)form1.FindControl("txt_object" + i.ToString())).Text.ToString();
Response.Write(objText);
}