Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2006, 06:14 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default find all the controls inside any table

hi
how can I find all the controls inside any table
i.e.
<TABLE id="Table2">
<TR>
<TD>Country</TD>
<TD><asp:DropDownList id="listCountry" runat="server"></TD>
</TABLE>
    ..........I want to pick the list control I have tried
FindControl method
thx in adv

Amartya

 
Old October 24th, 2006, 06:35 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Run you table as a server control then do this:

For Each ctrl as control in Table.Controls
   If TypeOf ctrl Is DropDownList then
    //Do something
   End if
Next

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 24th, 2006, 06:50 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

foreach (Control c in Table2.Controls)
            {
                Type t = c.GetType();
                Response.Write( t.Name+" ");
            }
this is my code and it gives
HtmlTableRow HtmlTableRow HtmlTableRow
but i need those server controls which i embded inside the table pls reply


 
Old October 24th, 2006, 06:54 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is it possible!
because table is htmlcontrols & on the other hand textbox etc are WebControls??

 
Old October 24th, 2006, 06:56 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually i want ids of each server controls inside a table is it possible??


 
Old October 24th, 2006, 06:57 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

i dont see why its not possible, i do this all the time with tables and panels and never have a problem returning my webcontrols?

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 24th, 2006, 07:03 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have given my codes also made table2 runat=server

 
Old October 24th, 2006, 07:29 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it's not working anyway thanks

 
Old October 24th, 2006, 08:04 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Make your loop recursive;

private void tableControls(){
 //This is your main loop
 foreach(Control c in Table.Controls){
  checkControls(c);
 }
}

private void checkControls(Control crl){
//This method can be recursive
if ((crl.GetType() == DropDownList)) {
//do something
}
else if ((crl.Controls.Count > 0)) {
    foreach (Control c in crl.Controls) {
        checkControls(c);
    }
}
}



-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 24th, 2006, 08:22 AM
Authorized User
 
Join Date: Oct 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot it's working






Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET COntrols inside XSLT sani723 XSLT 8 March 22nd, 2007 07:15 AM
How to get to controls inside DataList? rsearing ASP.NET 2.0 Basics 1 March 1st, 2007 09:14 AM
CreateUserWizard -access controls inside templates vs .NET Framework 2.0 0 September 13th, 2006 09:01 PM
databound grids with html controls inside badgolfer ASP.NET 1.0 and 1.1 Basics 1 September 25th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.