473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Iterating trough controls

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
3 1074
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Adam Parkin | last post by:
Hi all, what I want to do is write a function to toggle the enabled field of all controls within a frame, but what I can't figure out is how does one iterate through all controls in a frame object?...
1
by: Andrés Giraldo | last post by:
Hi! I'm trying to pass trough all the objects of a form but I have some text inputs in a DIV and I have many DIVs like this on my form. I'm doing something like: for (i = 0; i <...
0
by: Javier de la Torre | last post by:
Hi all, I'm wondering if someone has experiment problems using SQL statements with UNIONS trough the ODBC driver. For example this SQL statement: (SELECT DISTINCT compactes.numplec AS UnitId...
2
by: M Shafaat | last post by:
Hi! Consider the following: Object A is a member of Object B. Object A has a known identifier. Object B has an unknown identifier. How do we reference Object B using Object A? I have tried...
1
by: Jeremy | last post by:
I have been trying to iterate through the controls on my form and preset all textboxes to a cssClass. Unfortunately, I have been unable to figure out how to recursively move through sub-controls...
6
by: Dany P. Wu | last post by:
Hi everyone, I created a page which contains a two-column table. The first column has a bunch of labels, and the second a bunch of textboxes. Here's the code: ...
4
by: Milsnips | last post by:
hi there, i have a strange problem. I want to programatically loop through each control on a page, but am having issues. my test example: 1. header.ascx - the ascx control finds all the...
4
by: Ali | last post by:
I used to clear my page's control in Visual Studio 2003 using code like this: Dim c As Control For Each c In Page.Controls(1).Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = Nothing...
2
by: Bill44077 | last post by:
Hi, I am trying to iterate though the controls on a content page that has a master page so I can disable text. If it weren't on a content page it is simple: foreach (Control c in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.