Label.Text controls in an array

G

Guy Noir

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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

Guy Noir

Göran Andersson said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top