473,387 Members | 3,787 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.

Label.Text controls in an array

Hello again.
Quick Question:
I have a series of labels on my asp.net c# page: lbl128d, lbl64d,
lbl32d, lbl16d, lbl8d, lbl4d, lbl2d, lbl1d

I would like to place these in an array so that I can loop through them
to assign values to them.
I have the controls places on my page and I create an array like this
in page_load:

fourthLabels = new Label[8] {lbl128d, lbl64d, lbl32d, lbl16d, lbl8d,
lbl4d, lbl2d, lbl1d};

When I try to loop through them, it says I'm dealing with a null
reference exception....
I'm guessing that I have the array in the wrong place (page_load vs
somewhere else) and the controls don't exists when I create the
array.....

Can this be done? If so can you point me in a direction that will lead
to a solution?

Thanks much. I learn so much from this newsgroup.

-Guy

Nov 1 '06 #1
2 1354
Yes, it can be done, and that's how you do it.

How do you loop through the array, and what do you do with the labels?

Guy Noir wrote:
Hello again.
Quick Question:
I have a series of labels on my asp.net c# page: lbl128d, lbl64d,
lbl32d, lbl16d, lbl8d, lbl4d, lbl2d, lbl1d

I would like to place these in an array so that I can loop through them
to assign values to them.
I have the controls places on my page and I create an array like this
in page_load:

fourthLabels = new Label[8] {lbl128d, lbl64d, lbl32d, lbl16d, lbl8d,
lbl4d, lbl2d, lbl1d};

When I try to loop through them, it says I'm dealing with a null
reference exception....
I'm guessing that I have the array in the wrong place (page_load vs
somewhere else) and the controls don't exists when I create the
array.....

Can this be done? If so can you point me in a direction that will lead
to a solution?

Thanks much. I learn so much from this newsgroup.

-Guy
Nov 1 '06 #2
Göran Andersson wrote:
Yes, it can be done, and that's how you do it.

How do you loop through the array, and what do you do with the labels?
Nevermind. I had a stupid PEBKAC error. I was calling the loop before I
created the array *DOH*

It works now.

Thanks much for the response. Just had a logic lapse here for a
minute.....

-Guy

Guy Noir wrote:
Hello again.
Quick Question:
I have a series of labels on my asp.net c# page: lbl128d, lbl64d,
lbl32d, lbl16d, lbl8d, lbl4d, lbl2d, lbl1d

I would like to place these in an array so that I can loop through them
to assign values to them.
I have the controls places on my page and I create an array like this
in page_load:

fourthLabels = new Label[8] {lbl128d, lbl64d, lbl32d, lbl16d, lbl8d,
lbl4d, lbl2d, lbl1d};

When I try to loop through them, it says I'm dealing with a null
reference exception....
I'm guessing that I have the array in the wrong place (page_load vs
somewhere else) and the controls don't exists when I create the
array.....

Can this be done? If so can you point me in a direction that will lead
to a solution?

Thanks much. I learn so much from this newsgroup.

-Guy
Nov 1 '06 #3

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

Similar topics

0
by: Adonai | last post by:
Hi, I'm having an issue with this code that I'm writing, I'm curious as to why the windows form label (lblTime) isn't getting updated with the new variable when I use the timer. I made a blank form...
3
by: jhs | last post by:
Hello, I developping a .NET windows form application an need some help to create an array of System.Windows.Forms.Label in order to be able to manage all of them using index. I'm trying to do...
6
by: Joe | last post by:
I know that the Literal control will not render a <span> tag so I can not format its text. Other than this, what is the difference betwen the Literal control and the LiteralControl Control? How...
13
by: Lighting_dragon | last post by:
I try to make an array of label as this. Dim ArrLabel(10) as System.Windows.Forms.Label For i =0 to 10 ArrLabel(i) = New System.Windows.Forms.Label ArrLabel(i).Left=25 ArrLabel(i).Top=25*i...
31
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
7
by: anthony | last post by:
I know this is probably talk about millions of time here, but I cant seem to find a close one, I am so used to the vb6 control array, now that I have to use vb.net for my project, I like to do...
3
by: Neil Wallace | last post by:
Hi, This is an odd one. I've been struggling to get "double click" to work well for my controls. The same event handler works perfectly for buttons, but not for labels. Can anyone tell me...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
1
by: karthik25 | last post by:
Hi, The following code creates a tab container, 5 tab panels, buttons, labels. I was able to add event handlers to the button. But how am i supposed to access the dynamically created labels? For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.