Solved

ASP.NET - Finding controls within a table

Posted on 2009-07-07
9
250 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now