471,326 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Control Array

I am working on an ASP.net project with code behind in C#.
I must manipulate the contents of many label controls.
In visual basic (VB6) I could place all the controls into a control array
and then refer to an individual control it's index number.
I would like to do the same in C#.
Can someone suggest a method I should use ?
Thanks,
Jim
Dec 2 '05 #1
1 1705
The controls are already in a collection that you can iterate through.
The property is called Controls. The only thing is that it's *all*
the controls, so you have to check the type of each control instance in
the collection in order to find just the labels. Also you may have to
recurse to deal with controls that contain other controls (for example
in your scenario, now or in the future, some labels may be within panels).

This is a pain rather than just defining a control array, but it can be
done with utility code that you write once and forget. For example you
could get a simple ArrayList of label references back from a routine
that iterates the control collection, along the lines:

ArrayList myLabels =
Util.GetControlList(Controls,typeof(System.Web.Con trols.Label);

//or:

ArrayList myLabels = Util.GetControlsByNamePrefix(Controls,"lbl");

For some ideas, Google on something like:

..NET Controls iterate

Best,

--Bob

Jim McGivney wrote:
I am working on an ASP.net project with code behind in C#.
I must manipulate the contents of many label controls.
In visual basic (VB6) I could place all the controls into a control array
and then refer to an individual control it's index number.
I would like to do the same in C#.
Can someone suggest a method I should use ?
Thanks,
Jim

Dec 2 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by The Mess | last post: by
10 posts views Thread by James McGivney | last post: by
3 posts views Thread by Mark Broadbent | last post: by
6 posts views Thread by chxant | last post: by
2 posts views Thread by George | last post: by
14 posts views Thread by Jim Burns | last post: by

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.