.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Dynamic control creation

Posted By: preetu     Posted Date: March 05, 2010    Points:2   Category :ASP.Net
Thanks a lot!!!!!

i know that how can dynamic button control..

but my doubt is that..

here control's number is not fix..means it is dynamic also...

so how can i create there specific event....

i do something that...

If (CType(sender, Button).ID) = "btn" & i Then

this code gave control's id

so ...????

Author: abhay             
Posted Date: March 05, 2010     Points: 5   

Look at this example

for (int i = 0; i < 10; ++i)
Button btn = new Button();
btn.Text = "btn" + i.ToString() + "";
btn.ID = "btn_" + i.ToString() + "";
btn.Click += new EventHandler(btnSave_Click1);
btn.CommandName = i.ToString();
btn.CommandArgument = i.ToString();

protected void btnSave_Click1(object sender, EventArgs e)
Button btn = (Button)sender;

switch (int.Parse(btn.CommandName))
case 0:
call a function or write the code for first button click event
case 1:
call a function or write the code for second button click event
///go on like this


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend