looping through controls

G

Guest

hello, i got many asp.net controls and i want to put the same values into all
of the contorls. is there a better coding habit to allow me to loop through
all these contorls with different id to have the same attribute. e.g css
class name or height or enable/disable it. thanks
 
E

Ersin Gençtürk

sure,

you can do something like this :

foreach(Control ChildControl in pnlDocument.Controls[0].Controls) //get
child controls of a objcet , this can be page itself
{
if (ChildControl.GetType()==typeof(Controls.ErsinContent)) // check the
type of the object if this is one of your objects
{
Controls.ErsinContent
Content=(ErsinPortal.Controls.ErsinContent)ChildControl; //cast object as
your object
Content.Content=ContentRow.Content; //change properties
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top