how loop through various labels' text values

Discussion in 'ASP .Net' started by tony collier, Jan 12, 2004.

  1. tony collier

    tony collier Guest

    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
    }

    then on next 2 loops:


    label_2.text=labelarray

    and

    label_3.text=labelarray



    etc.etc.
     
    tony collier, Jan 12, 2004
    #1
    1. Advertising

  2. 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
    }

    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
    }

    Hope it helps. Cheers,

    Gerben.

    "tony collier" <> wrote in message
    news:Xns946E16E88F6BEmelakkahotmailcom@140.99.99.130...
    > 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
    > }
    >
    > then on next 2 loops:
    >
    >
    > label_2.text=labelarray
    >
    > and
    >
    > label_3.text=labelarray
    >
    >
    >
    > etc.etc.
    >
    >
    >
    >
     
    Gerben van Loon, Jan 12, 2004
    #2
    1. Advertising

  3. tony collier

    tony collier Guest

    "Gerben van Loon" <> 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.
     
    tony collier, Jan 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weng Tianxiang
    Replies:
    5
    Views:
    1,357
    Christophe
    Feb 16, 2006
  2. Roedy Green
    Replies:
    3
    Views:
    459
    Mike Schilling
    Sep 13, 2008
  3. Tom Fitzgibbon

    loop through text object values in DOM?

    Tom Fitzgibbon, Dec 4, 2003, in forum: Javascript
    Replies:
    2
    Views:
    123
    Tom Fitzgibbon
    Dec 4, 2003
  4. Nene

    Using loop labels and iterating.

    Nene, Feb 17, 2012, in forum: Perl Misc
    Replies:
    7
    Views:
    473
    John W. Krahn
    Feb 18, 2012
  5. Isaac Won
    Replies:
    9
    Views:
    460
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page