473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to create Dynamic Control(Label) in asp.net with c#

I have created the Dynamic control in asp.net c#
like

for (int i = 1; i <= 5; i++)
{
Label label = new Label();
label.ID = "Label" + i;
label.Text = "Label"+i;
form1.Controls.Add(label);
}

problem is how to get label1or label2 etc control outside this
function..it is accessiable outside this..plz help me in solving this
problem

Jun 29 '07 #1
1 7079
You should be able to access the controls using the FindControl method.

for (int i = 1; i <= 5; i++)
{
Label label = new Label();
label.ID = "Label" + i;
label.Text = "Label" + i;
form1.Controls.Add(label);
}

((Label)form1.FindControl("Label1")).Text = "Hello, Label 1!<br/>";
((Label)form1.FindControl("Label2")).Text = "Hello, Label 2!<br/>";
((Label)form1.FindControl("Label3")).Text = "Hello, Label 3!<br/>";
((Label)form1.FindControl("Label4")).Text = "Hello, Label 4!<br/>";
((Label)form1.FindControl("Label5")).Text = "Hello, Label 5!<br/>";

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com
I have created the Dynamic control in asp.net c#
like
for (int i = 1; i <= 5; i++)
{
Label label = new Label();
label.ID = "Label" + i;
label.Text = "Label"+i;
form1.Controls.Add(label);
}
problem is how to get label1or label2 etc control outside this
function..it is accessiable outside this..plz help me in solving this
problem

Jun 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark | last post by:
How do you reference the caption of the label attached to a control on a form by first referencing the form? For example, textbox named Addr1 has an attached label with the caption "Address1"....
4
by: Fabrizio | last post by:
Hi I would like to create a label at runtime and show it on a web form, but once i create doesn't appear anywher How can I add the control on the web form so I can see it thank yo Fabrizio
3
by: Tracey | last post by:
My application requires to create labels with varied length at runtime. But I don't know how to do that. However, the font of string displayed in label is different, how can I decide the length...
1
by: mail2madhur | last post by:
I need to display different text on label on click of button. <table> <tr> <td> ?????</td> </tr> <tr> <td> <TEXTAREA id="notesId" name="notesdescDisplay" rows=12 cols=83 value=""></TEXTAREA>...
1
by: jjluna13 | last post by:
Hello, I have two textboxes and one label in a form. I am looking to display the sum of both textboxes in the label on "real time", in fact to execute the sum when I lost the focus of one of the...
5
by: blackwellam | last post by:
Hi, Firstly apologies for asking a similar question to one I know has been covered before but I'm quite new to visual basic and dont really understand the answers or how to get the next step. Im...
1
by: Ronald S. Cook | last post by:
How can I create a label array at design time in a .NET Windows forms app? Thanks, Ron
5
by: prokopis | last post by:
hi. i need some help with a problem that come up. am using c# with windows applications i have dynamical link labels that appeared on the screen. is it possible to capture the text name of the link...
8
devonknows
by: devonknows | last post by:
Hi, I have a property page for my user control that has a text box and a button on it, when the user enters text into the text box and clicks the button i want a new label to appear on the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.