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


Top 5 Contributors of the Month
david stephan

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

Responses
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();
div1.Controls.Add(btn);
}


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
break;
case 1:
call a function or write the code for second button click event
break;
///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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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