Tuesday, July 15, 2008

Dynamic Creation of Controls

Output:












Firstly add a panel control ,a textbox and a button to design page .when we enter a number in textbox at run time ,the same number controls are created at runtime.


Source Code:

protected void btninsert_Click(object sender, EventArgs e)
{
int count =Convert.ToInt32(TextBox1.Text);
Panel1.Controls.Clear();
Table tb = new Table();
tb.GridLines = GridLines.Both;
for (int i = 0; i < count; i++)
{

TableCell c1 = new TableCell();
TableRow rw = new TableRow();
TextBox tx = new TextBox();
c1.Controls.Add(tx);
rw.Cells.Add(c1);
tb.Rows.Add(rw);
}
Panel1.Controls.Add(tb);
}

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...