.NETGURU
Creating Labels dynamically
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Uma Ayyanathan
<html><div style='background-color:'><DIV>
<P><BR>Hi everybody,</P>
<P>How do you create an array of labels dynamically at Page Load or at runtime.  The labels should be<BR>Label1 or Label(1)<BR>Label2 or Label(2)  etc...</P>
<P>I tried in the Page Load event the following code:</P>
<P>  For count = 0 To maxcount<BR>   Dim lbRolenamenew() as Array<BR>   lbRolenamenew(count) = New Label()<BR>   Page.Controls.Add(lbRolenamenew(count))<BR>  Next</P>
<P>It didn't work!</P>
<P>Any ideas on this is appreciated.</P>
<P>Thanks,<BR>Uma</P></DIV>
<DIV></DIV>
<DIV></DIV></div><br clear=all><hr>Send and receive Hotmail on your mobile device: <a href='http://g.msn.com/1HM1ENUS/c152??PI=44364'>Click Here</a><br></html>

Reply to this message...
 
    
Mike Simon
dHJ5IHRoaXMgDQpkaW0gbWF4Y291bnQgYXMgaW50ZWdlciA9NQ0KZGltIGxibHRtcCBhcyBzeXN0
ZW0ud2ViLnVpLndlYmNvbnRyb2xzLmxhYmVsDQogDQpmb3IgaT0wIHRvIG1heGNvdW50DQogICBs
Ymx0bXA9IG5ldyBzeXN0ZW0ud2ViLnVpLndlYmNvbnRyb2xzLmxhYmVsDQogICBsYmx0bXAuaWQ9
ImlkIiAmIGkNCiAgIHBhZ2UuY29udHJvbHMuYWRkKGxibHRtcCkNCm5leHQNCiANCiANCiANCg0K
CS0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tIA0KCUZyb206IFVtYSBBeXlhbmF0aGFuIA0KCVNl
bnQ6IFR1ZSA4LzEzLzIwMDIgMTI6MzYgUE0gDQoJVG86IGFzcG5nZnJlZWZvcmFsbCANCglDYzog
DQoJU3ViamVjdDogW2FzcG5nZnJlZWZvcmFsbF0gQ3JlYXRpbmcgTGFiZWxzIGR5bmFtaWNhbGx5
DQoJDQoJDQoNCgkNCglIaSBldmVyeWJvZHksDQoNCglIb3cgZG8geW91IGN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<%@ Page Language="VB" Debug="False" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
dim count as integer
For count = 1 To 20
Dim lbRolenamenew = New Label()
lbRolenamenew.Visible = true
lbRolenamenew.Text = "My name is - " & count
PlaceHolder1.Controls.Add(lbRolenamenew)
Next
End Sub
</script>

<html>
<head>
</head>
<form runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server" />
</form>
</body>
</html>

- Srinivasa Sivakumar
Author, Developer and Reviewer
http://www3.brinkster.com/webguru/

Latest Books:
=========Visual Basic .NET Threading Handbook
http://www.amazon.com/exec/obidos/ASIN/1861007132

ASP.NET Security
http://www.amazon.com/exec/obidos/ASIN/1861006209

----- Original Message -----
From: Uma Ayyanathan
To: aspngfreeforall
Sent: Tuesday, August 13, 2002 12:36 PM
Subject: [aspngfreeforall] Creating Labels dynamically

Hi everybody,

How do you create an array of labels dynamically at Page Load or at runtime. The labels should be
Label1 or Label(1)
Label2 or Label(2) etc...

I tried in the Page Load event the following code:

For count = 0 To maxcount
Dim lbRolenamenew() as Array
lbRolenamenew(count) = New Label()
Page.Controls.Add(lbRolenamenew(count))
Next

It didn't work!

Any ideas on this is appreciated.

Thanks,
Uma

------------------------------------------------------------------------------
Send and receive Hotmail on your mobile device: Click Here
| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/aspngfreeforall = JOIN/QUIT | news://ls.asplists.com = NEWSGROUP
Reply to this message...
 
 
System.EventArgs
System.Web.UI.Page
System.Web.UI.WebControls.PlaceHolder




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification