Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET - Finding controls within a table

Posted on 2009-07-07
9
Medium Priority
?
301 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

824 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