By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Iterating trough controls

P: n/a
I want to know if there is a way to easily iterate trough all the controls
contained, say, in a table, including the controls that can be inside the
cells and in any nested tables that are inside?

Regards,

Sandra
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Here is an example which you could expand on. All controls inherit from
Control, so you can walk as far as you want before you decide what kind of
control it is. This could be re-factored to be recursive if it made sense in
your application.

Dim tbl As HtmlTable

For Each c As Control In Me.Controls
If c.GetType Is GetType(HtmlTable) Then
tbl= c
Exit For
End If
Next
For Each c As Control In tbl.Controls
Select Case c.gettype.tostring

Case "System.Web.UI.WebControls.TextBox"
..
..
..
for each c1 as control in c.controls
Nov 18 '05 #2

P: n/a
You can write a recursive function that takes a System.Web.UI.Control as an
argument, and searches (loops) through its' Child Controls Collection for
whatever it is you're trying to achieve. If it doesn't find what it is
looking for, it calls itself for each Child Control, passing the Child
Control to the instance of the function. This will in essence, "drill down"
into the entire Child Controls hierarchy under a given Control.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Sandra Castellanos" <sa*****@washuway.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
I want to know if there is a way to easily iterate trough all the controls
contained, say, in a table, including the controls that can be inside the
cells and in any nested tables that are inside?

Regards,

Sandra

Nov 18 '05 #3

P: n/a
http://www.aspnet101.com/aspnet101/tips.aspx?id=97

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Sandra Castellanos" <sa*****@washuway.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
I want to know if there is a way to easily iterate trough all the controls
contained, say, in a table, including the controls that can be inside the
cells and in any nested tables that are inside?

Regards,

Sandra

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.