如何动态地将控件添加到ASP.NET表单?

问题描述:

我不知道该如何动态地添加控件使用C#.NET的形式。谁能帮我?我知道这与vb.net,但我需要知道在C#的语法。

I do not know how to add controls dynamically to the form using C# .net. Can anyone help me? I know this with vb.net but I need to know the syntax in C#.

在形式,下面的代码就可以动态地添加一个按钮:

In the form, the following code can add a button dynamically:

Button button1 = new Button();
button1.Text = "dynamic button";
button1.Left = 10; button1.Top = 10;  //the button's location
this.Controls.Add(button1);