Solved

ASP.NET - Finding controls within a table

Posted on 2009-07-07
9
275 Views
Last Modified: 2012-05-07
Hello Experts,

I'm trying to find all controls within a table, to do 'something' to them.  Seems like it should work, but it doesn't find them.  Any way I can get this to work?

Thanks!
For Each objControl As Control In tblFormatting.Controls
            If TypeOf objControl Is TextBox Then
                'Do Something
            ElseIf TypeOf objControl Is DropDownList Then
                'Do Something
            ElseIf TypeOf objControl Is RadioButtonList Then
                'Do Something
            End If
        Next

Open in new window

0
Comment
Question by:GRCHELPDESK
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 24794947
1. Is tblFormatting has a "runat=server" attibute?
2. In tblFormatting, is there any other control such as Panel that wraps around the TxttBox, DropDownList controls? If yes, then you will need to loop through the Panel control as well.
0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 24795002
Hi prairiedog,
1) tblFormatting is a table that I use to format all of the controls on my page.  It's a server control.
2) I don't have any panels or anything which wraps around the controls.
I'd be ok with a snippet of code that checks all controls on the page as well, I'm just not sure how to write it.
Thanks!
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24795112
Here is what you need to do:
1. you need add another loop to check each row of the table
2. Then in each row,you will need another loop to check each cells
3. Finally, in each cell, use your For Each loop to find controls.
BTW, is tblFormatting a reall server control, or an HTML table with "runat=server"?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 24795128
Ack ... didn't think it would be that complicated.
It's an HTML table with runat='server'
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 24795174
It will be something like this:
 

For Each tr As HtmlTableRow In tblFormatting.Rows
   For Each tc As HtmlTableCell In tr.Cells
      For Each objControl As Control In tc.Controls
          If TypeOf objControl Is TextBox Then
             'Do Something
          End If
      Next
   Next
Next

Open in new window

0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 24795231
ahhh, I think I get it.  Ok, let me mess with that, thanks for the help!
0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 24795289
Works like a charm, thank-you for your help on this!!
0
 
LVL 2

Author Closing Comment

by:GRCHELPDESK
ID: 31600604
Great Solution, and you really saved me a headache!
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24795300
You are welcome. Glad it worked for you.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question