View Full Version : C# help needed
hirky
December 2, 2005, 04:39 PM
I have a web form with some controls. How do access these controls in the program? What I have is a form with some drop down list. In the code, I would want to do a while loop that loops through each control on the form and test if its a dropdown list and perform some action if it is. The problem is that I don't know how to access a list of the controls so I can loop through. Any suggestions are welcome. Thanks in advance.
crosswire
December 2, 2005, 09:11 PM
check out the Page class in the Framework Documentations. Look at Page.Control
You can use that to easily iterate over all the server controls in the page.
This does not help much in terms of code, but you may find some snippets in the docs.
DigitHead
December 6, 2005, 10:10 PM
Something along the lines of:
foreach(Control c in this.Controls)
{
TextBox t = c as TextBox;
if (t != null)
t.Text = "test";
}
should get you going
hirky
December 7, 2005, 10:09 AM
Yow DigitHead, da ting deh work for me, respect yute, thanks also to crosswire!
DigitHead
December 7, 2005, 10:05 PM
Glad I could help. Make sure you pass on the knowledge someday.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.