Loop through webcontrol names

Results 1 to 2 of 2

Thread: Loop through webcontrol names

  1. #1
    Join Date
    Dec 1969

    Default Loop through webcontrol names

    Hello!<BR><BR>I am pretty novice, so if someone could help me with this I would be very grateful!<BR><BR>I have a lot of imagebuttons I would like to loop through with a for loop rather than using if statements on each imagebutton:<BR><BR>Image1.URL = "....";<BR>Image2.URL = "....";<BR>Image3.URL = "....";<BR>.<BR>.<BR>.<BR>How do I replace the numbers in Image1 and Image2 and so on with the for-loop counting variable?<BR><BR>Like this?<BR><BR>for (int i=0; i&#060;10; i++)<BR> Image+i.URL = "...";<BR><BR>Does anyone know how to do this?<BR>Please help me!!!<BR><BR>Thank you!<BR><BR>Espen Hoff<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Loop through webcontrol names

    i dont&#039; this is the right way, but i tried it and it worked fine.<BR>see what you can do to make more right !<BR>[code language="C#"]<BR>for (int i=1; i&#060;=4; i++ )<BR> {<BR> Button me = (Button)this.FindControl("WebForm1").FindControl(" Button" + i.ToString());<BR> me.BackColor = Color.FromName("red");<BR> }<BR>[/code]<BR><BR>i tried to use FOREACH but it seems that htmlform control isn&#039;t enumerable!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts