Hello,
I have a panel which contains various textboxes and dropdownlists.
I want to loop through each control inside the panel and detected if it
is a DropDownList or a TextBox so I can access its SelectedValue or
Text.
How can I do this?
Thanks,
MiguelHi,
shapper wrote:
> Hello,
> I have a panel which contains various textboxes and dropdownlists.
> I want to loop through each control inside the panel and detected if it
> is a DropDownList or a TextBox so I can access its SelectedValue or
> Text.
> How can I do this?
> Thanks,
> Miguel
foreach ( Control child in yourPanel.Controls )
{
if ( child is DropDownList )
{
( (DropDownList) child ).SelectedValue = "...";
}
if ( child is TextBox )
{
( (TextBox) child ).Text = "...";
}
}
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
This is good only if the controls are directly in the panel. Otherwise a
recursion is needed.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Laurent Bugnion [MVP]" <galasoft-lb@.bluewin.ch> wrote in message
news:%23NoAEFYNHHA.5064@.TK2MSFTNGP04.phx.gbl...
> Hi,
> shapper wrote:
> foreach ( Control child in yourPanel.Controls )
> {
> if ( child is DropDownList )
> {
> ( (DropDownList) child ).SelectedValue = "...";
> }
> if ( child is TextBox )
> {
> ( (TextBox) child ).Text = "...";
> }
> }
> HTH,
> Laurent
> --
> Laurent Bugnion [MVP ASP.NET]
> Software engineering: http://www.galasoft-LB.ch
> PhotoAlbum: http://www.galasoft-LB.ch/pictures
> Support children in Calcutta: http://www.calcutta-espoir.ch
Hi,
Eliyahu Goldin wrote:
> This is good only if the controls are directly in the panel. Otherwise a
> recursion is needed.
Yes, but the OP said "I have a panel which contains various textboxes
and dropdownlists."
Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
0 comments:
Post a Comment