Solved

ASP.NET - Finding controls within a table

Posted on 2009-07-07
9
268 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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