下面请跟着图老师小编一起来了解下C#动态添加控件,精心挑选的内容希望大家喜欢,不要忘记点个赞哦!
【 tulaoshi.com - 编程语言 】
能动态添加就是不怎会定位....
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);
}
得到文本框里面得值
(本文来源于图老师网站,更多请访问http://www.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);
}
来源:http://www.tulaoshi.com/n/20160219/1600743.html