By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

For each...next question

P: n/a
I know this was asked before, but I never saw what the answer was...

I have a webform (asp.net) that has a number of dropdownlists (and other
controls). I am trying to use a For Each...Next loop to run through
each of them to enable or disable them. I cannot seem to find the
correct element variable/collection combination to do this.

Does anyone know what I need to do to make the loop work??

Thanks,

Derek

Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
there is a better group for this, but the best way I would do it would be to
cycle through the page controls recursivly (Ahh CJ brings up the recursion
crap again)...

so basically

public function findControl (pControl as Control, pType as system.type) as
Control
for each tControl in pControl.Controls
if (tControl.getType() = pType) then
return tControl
elseif (pControl.Controls.Count > 0) then
tControl = findControl(tcontrol, pType)

end if
next

end function

This is very rudimentary and you'll probaby have to change most of this
code, but its a building block to find it...

This is also complex, you could also search the controls names and see if
its what you want too... probably more effective....

Take care and hope it helps.

CJ
"Tangent" <ta*****@covad.net> wrote in message
news:bk**********@sun-news.laserlink.net...
I know this was asked before, but I never saw what the answer was...

I have a webform (asp.net) that has a number of dropdownlists (and other
controls). I am trying to use a For Each...Next loop to run through
each of them to enable or disable them. I cannot seem to find the
correct element variable/collection combination to do this.

Does anyone know what I need to do to make the loop work??

Thanks,

Derek

Nov 20 '05 #2

P: n/a
Hello,

"CJ Taylor" <no****@blowgoats.com> schrieb:
there is a better group for this, but the best way I would
do it would be to cycle through the page controls
recursivly (Ahh CJ brings up the recursion crap again)...

so basically


\\\
public function EnumControls( _
pControl as Control, _
pType as system.type _
) as Control
for each tControl in pControl.Controls
if (tControl.getType() = pType) then
ModifyControl(tControl)
end if
if pControl.Controls.Count > 0 then
EnumControls(tcontrol, pType)
end if
next
end function
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

P: n/a
Thank you Herfried. =)
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
Hello,

"CJ Taylor" <no****@blowgoats.com> schrieb:
there is a better group for this, but the best way I would
do it would be to cycle through the page controls
recursivly (Ahh CJ brings up the recursion crap again)...

so basically


\\\
public function EnumControls( _
pControl as Control, _
pType as system.type _
) as Control
for each tControl in pControl.Controls
if (tControl.getType() = pType) then
ModifyControl(tControl)
end if
if pControl.Controls.Count > 0 then
EnumControls(tcontrol, pType)
end if
next
end function
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #4

P: n/a
Hello,

"Tangent" <ta*****@covad.net> schrieb:
I know this was asked before, but I never saw what the
answer was...


In addition to the other replies:

You may want to turn to the ng for ASP.NET Web Controls questions for future
ASP.NET related questions:

news://msnews.microsoft.com/microsof...et.webcontrols

Web interface:

http://msdn.microsoft.com/newsgroups...et.webcontrols

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5

P: n/a
I'll do that - thank you!

Herfried K. Wagner [MVP] wrote:
Hello,

"Tangent" <ta*****@covad.net> schrieb:
I know this was asked before, but I never saw what the
answer was...

In addition to the other replies:

You may want to turn to the ng for ASP.NET Web Controls questions for future
ASP.NET related questions:

news://msnews.microsoft.com/microsof...et.webcontrols

Web interface:

http://msdn.microsoft.com/newsgroups...et.webcontrols


Nov 20 '05 #6

P: n/a
Cor
Hi Tangent,
I don't know if the code from the others work, but there is a different in
the for each loop with controls on a window form and a webform
When you read in the documentation
dim ctr as control
for each ctr in controls
if typeof ctr is textbox
ctr.text = "Y"
end if
next
That is as far as I know not possible with a webform the type of a control
is not known when a page is loading and after that
(you can find it in the knowledge base I thougth that you have to search for
type and webform)

Maybe this helps you in stopping searching for strange things that happens.
Cor

Nov 20 '05 #7

P: n/a
It looks like that my problem was more elementary than the recursion.
My dropdowns are child controls, so when I ran through the top-level
controls of the form, they weren't being looked at by the code. So,
with the combination of dropping the loop down to the child level and
cycling through the controls recursively, I finally got it to work.

Thanks for you help.

Derek

CJ Taylor wrote:
there is a better group for this, but the best way I would do it would be to
cycle through the page controls recursivly (Ahh CJ brings up the recursion
crap again)...

so basically

public function findControl (pControl as Control, pType as system.type) as
Control
for each tControl in pControl.Controls
if (tControl.getType() = pType) then
return tControl
elseif (pControl.Controls.Count > 0) then
tControl = findControl(tcontrol, pType)

end if
next

end function

This is very rudimentary and you'll probaby have to change most of this
code, but its a building block to find it...

This is also complex, you could also search the controls names and see if
its what you want too... probably more effective....

Take care and hope it helps.

CJ
"Tangent" <ta*****@covad.net> wrote in message
news:bk**********@sun-news.laserlink.net...
I know this was asked before, but I never saw what the answer was...

I have a webform (asp.net) that has a number of dropdownlists (and other
controls). I am trying to use a For Each...Next loop to run through
each of them to enable or disable them. I cannot seem to find the
correct element variable/collection combination to do this.

Does anyone know what I need to do to make the loop work??

Thanks,

Derek



Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.