Label.Text controls in an array

  • Thread starter Thread starter Guy Noir
  • Start date Start date
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
 
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ö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
 
Back
Top