473,499 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

loop through variables?

aas4mis
97 New Member
In this for loop is it possible to reference a different label with each iteration?

c#
Expand|Select|Wrap|Line Numbers
  1.  for (x = 1;x <=3; x++) 
  2. {
  3. label & x.tostring & .visible = true;
  4. }
  5.  
Sorry for the mess of code. That was the only way I know how to get my point across. I'm used to php and vb, my c# is embarrassing.
Jun 16 '08 #1
7 1252
Plater
7,872 Recognized Expert Expert
You can loop through the controls inside an object (like a form or page) and check their .Name property?
I think is also a .FindControl(string) function that can do similar.
Jun 16 '08 #2
aas4mis
97 New Member
You can loop through the controls inside an object (like a form or page) and check their .Name property?
I think is also a .FindControl(string) function that can do similar.
this.FindControl() doesn't show as a valid command. I'm able to get what I need by the following:
Expand|Select|Wrap|Line Numbers
  1.             if (label1.Visible == true)
  2.  
  3.             {
  4.  
  5.                 label1.Visible = false;
  6.  
  7.                 label2.Visible = true;
  8.  
  9.                 label3.Visible = false;
  10.  
  11.             }
  12.  
  13.             else if (label2.Visible == true)
  14.  
  15.             {
  16.  
  17.                 label1.Visible = false;
  18.  
  19.                 label2.Visible = false;
  20.  
  21.                 label3.Visible = true;
  22.  
  23.             }
  24.  
  25.             else if (label3.Visible == true)
  26.  
  27.             {
  28.  
  29.                 label1.Visible = true;
  30.  
  31.                 label2.Visible = false;
  32.  
  33.                 label3.Visible = false;
  34.  
  35.             }
  36.  
There has to be a better way of getting this done? Any suggestions? This is done after a button click.
Jun 16 '08 #3
Plater
7,872 Recognized Expert Expert
this.FindControl(myString) worked for me.
Are you in a windows application and not a web application maybe?
Jun 16 '08 #4
aas4mis
97 New Member
this.FindControl(myString) worked for me.
Are you in a windows application and not a web application maybe?
yes, I'm in windows application
Jun 17 '08 #5
Plater
7,872 Recognized Expert Expert
ah ha! You had said you came from php so I fugred you must be doing a webbased app (well I guess there's TK and console uses for php too)
You would have to loop through the controls checking the name property then.
Jun 17 '08 #6
aas4mis
97 New Member
ah ha! You had said you came from php so I fugred you must be doing a webbased app (well I guess there's TK and console uses for php too)
You would have to loop through the controls checking the name property then.
My c# abilities are poor. I like the IDE and intellisense that VS has and want to start learning c# instead of improving on my VB. Would you mind showing me a loop for controls?
Jun 17 '08 #7
Plater
7,872 Recognized Expert Expert
Something like this:
Expand|Select|Wrap|Line Numbers
  1. private Control FindControl(Control startcontrol, string ControlName)
  2. {
  3.     Control retval = null;
  4.     foreach (Control c in startcontrol.Controls)
  5.     {
  6.         if (c.Name.Equals(ControlName))
  7.         {
  8.           retval = c;
  9.           break;
  10.         }
  11.         if (c.HasChildren)
  12.         {
  13.           Control temp = FindControl(c, ControlName);
  14.           if (temp != null)
  15.           {
  16.             retval = temp;
  17.             break;
  18.           }
  19.         }
  20.     }
  21.     return retval;
  22. }
  23.  
Jun 17 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2314
by: z0ink | last post by:
I am working on a small graphing application. In the process of graphing I use 3 seperate scripts for getting the job done. The first is the page that the use sees and selects all the data from. ...
33
3512
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
0
2544
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
12
4870
by: reynoldscraigr | last post by:
Hi All, hope someone can see what wrong here I have the following function function RemoveMenuFromHoldArray(menuName) { var i = 0; for (i=0;i<=MenusToHoldOpen.length-1;i++) { if...
32
4591
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
7
2673
by: Rajeev | last post by:
Hello, I'm using gcc 3.4.2 on a Xeon (P4) platform, all kinds of speed optimizations turned on. For the following loop R=(evaluate here); // float N=(evaluate here); // N min=1 max=100...
32
2553
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
6
3026
by: tcurdts | last post by:
Greetings, I'm using WindowsXP Pro v5.1and am writing a BAT file to loop through a list of files (contained in a .txt file) and pass them (actually variables derived from them) to another program...
4
1615
by: chellemybelle | last post by:
Hello, I basically have made a little cheezy slideshow and would like to add captions to each pic as it loops through. I've tried everything I can think of. I'm assuming I might need to use an...
5
1556
by: vippstar | last post by:
Hello comp.lang.c I had to write a for() loop with two temporary variables for it. What I *usually* do is define the variables at the top so it works in C89 as well. But I realized that it just...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.