German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


How to add array of Buttons / Controls to the ASP .NET Page ?

Written by kamal on Jun 29, 2007
Adding ASP .NET Controls to the Form

Explanation:

some time we need to add a Number of same controls to the Page. Following is the code:

Button[] BtnArray=new Button[10];

for (int i = 0; i < 10; i++)
{
BtnArray[i] = new Button();
BtnArray[i].Width = 100;
BtnArray[i].Text = @"Button " + i.ToString();
Page.Form.Controls.Add(BtnArray[i]);
BtnArray[i].Click += new EventHandler(TestMe_Click);
}

void TestMe_Click(object sender, EventArgs e){

Label1.Text = ((Button)sender).Text;
 
}

 

Visitors/Readers Comments
(for questions please use The Forum)



"Be the First to Comment!"


Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)