asp.net怎么动态添加控件
asp.net如何动态添加控件C# codeprotected void Page_Load(object sender, EventArgs e){TextBox tb new
asp.net如何动态添加控件
C# code protected void Page_Load(object sender, EventArgs e) { TextBox tb = new TextBox(); tb.Text = "sss"; this.AddedControl(tb,2); }
请问我如何将它添加进页面显示?
[解决办法]在你的页面上定义一个panel
<Asp:panel id="Pnl1"></Asp:panel>
然后,你的后台就可以为之添加控件了:
protected void Page_Load(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.Text = "sss";
Pnl1.Controls.Add(tb);
}
[解决办法]不一定用panel!!
最简洁的代码是:
TextBox tb = new TextBox();
tb.Text = "sss";
this.form1.Controls.Add(tb);