Solved

ASP.NET - Finding controls within a table

Posted on 2009-07-07
9
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

627 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