Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how loop through various labels' text values

Reply
Thread Tools

how loop through various labels' text values

 
 
tony collier
Guest
Posts: n/a
 
      01-12-2004
hi

i have various labels on my page with ID's label_1, label_2 , label_3 etc.

How can i write a loop that sequentially changes their text values to
values i have in an array eg;.

for (i=0;i<max;i++){
label_1.text = labelarray[i]
}

then on next 2 loops:


label_2.text=labelarray[i]

and

label_3.text=labelarray[i]



etc.etc.




 
Reply With Quote
 
 
 
 
Gerben van Loon
Guest
Posts: n/a
 
      01-12-2004
Hi Tony,

You could put the labels in an arraylist and then use the foreach statement
to go through this list. This will look something like this:

ArrayList labellist = new ArrayList()
labellist.add(label_1)
labellist.add(label_2)
labellist.add(label_3)

//Loop throught the list of labels
foreach(Label lbl in labellist)
{
lbl.text = labelarray[i]
}

Or if this affects ALL labels which are on your page you could loop trough
the Page.Controls property

foreach(Label lbl in Page.Controls)
{
lbl.text = labelarray[i]
}

Hope it helps. Cheers,

Gerben.

"tony collier" <(E-Mail Removed)> wrote in message
news:Xns946E16E88F6BEmelakkahotmailcom@140.99.99.1 30...
> hi
>
> i have various labels on my page with ID's label_1, label_2 , label_3 etc.
>
> How can i write a loop that sequentially changes their text values to
> values i have in an array eg;.
>
> for (i=0;i<max;i++){
> label_1.text = labelarray[i]
> }
>
> then on next 2 loops:
>
>
> label_2.text=labelarray[i]
>
> and
>
> label_3.text=labelarray[i]
>
>
>
> etc.etc.
>
>
>
>



 
Reply With Quote
 
 
 
 
tony collier
Guest
Posts: n/a
 
      01-12-2004
"Gerben van Loon" <(E-Mail Removed)> wrote in news:btu7nd$r2t$1
@news2.tilbu1.nb.home.nl:

> ArrayList labellist = new ArrayList()
> labellist.add(label_1)
> labellist.add(label_2)
> labellist.add(label_3)
>


fantastic! thanks a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Re: How to loop through a list while inside the loop, the list size may be decreased? Roedy Green Java 3 09-13-2008 01:51 AM
loop through delimited values in string JR Java 6 06-23-2007 12:58 PM
loop through text object values in DOM? Tom Fitzgibbon Javascript 2 12-04-2003 09:41 PM
Loop Inside loop for writing text lines Aggelos ASP General 2 11-12-2003 09:59 AM



Advertisments