473,779 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1088
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(HtmlTab le) Then
tbl= c
Exit For
End If
Next
For Each c As Control In tbl.Controls
Select Case c.gettype.tostr ing

Case "System.Web.UI. WebControls.Tex tBox"
..
..
..
for each c1 as control in c.controls
Nov 18 '05 #2
You can write a recursive function that takes a System.Web.UI.C ontrol 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*****@washuw ay.com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.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*****@washuw ay.com> wrote in message
news:OZ******** ******@TK2MSFTN GP09.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
23827
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? For example, if I wanted to iterate through all controls in a form, I'd write something like: Dim x For Each x In frmMyForm.Controls x.Enabled = Not x.Enabled
1
4186
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 < document.forms(0).item.length; i++) { dosomethingwith(document.forms(0).item(i)); }
0
321
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 FROM compactes) UNION
2
1265
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 using "owner", "container", "parent", etc. without success. Please help.
1
3217
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 and all of my textboxes are in asp panels. The code I have can see the panels but not what is in them. Help please. Current code:
6
1296
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: ====================================================== Protected WithEvents Container As System.Web.UI.WebControls.PlaceHolder Private Sub ConstructEditTable() Container.Controls.Add(New LiteralControl("<table>" & vbNewLine))
4
1685
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 child controls no problems 2. default.aspx - i dont find any controls that are placed directly on the
4
4429
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 End If If TypeOf c Is DropDownList Then CType(c, DropDownList).SelectedIndex = 0 End If Next
2
2572
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 Page.Controls) { if (c is TextBox) {
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.