Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Loop through every control

Reply
Thread Tools

Loop through every control

 
 
shapper
Guest
Posts: n/a
 
      01-11-2007
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

 
Reply With Quote
 
 
 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      01-11-2007
Hi,

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
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      01-11-2007
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]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> 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



 
Reply With Quote
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      01-11-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Re: How to loop through a list while inside the loop, the list size may be decreased? Roedy Green Java 3 09-13-2008 01:51 AM
Explorer.exe error report every time access every type of video me =?Utf-8?B?SXJ3YW5zeWFo?= ASP .Net 4 10-30-2007 07:49 AM
Fastest Way To Loop Through Every Pixel Chaos Python 30 08-05-2006 11:13 PM
Loop Through Server Control - Refer Code (VB.NET) Sudhakar S P ASP .Net 0 10-08-2004 10:08 PM



Advertisments