How to add controls dynamically to ASP.NET form?

后端 未结 6 1796
说谎
说谎 2021-01-12 02:16

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#.

6条回答
  •  天命终不由人
    2021-01-12 02:38

    Below is the code to add controls dynamically to ASP.NET form.

    1. Initialize a label
    2. Assign text to it.
    3. Initialize a panel
    4. Add the label object to the panel.
         Label lbl1 = new Label();
         lbl1.Text = "Your message here";
         Panel panel1= new Panel();
         panel1.Controls.Add(lbl1);
    

提交回复
热议问题