For each...next question

  • Thread starter Thread starter Tangent
  • Start date Start date
T

Tangent

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
 
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
 
Hello,

CJ Taylor said:
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
///
 
Thank you Herfried. =)


Herfried K. Wagner said:
Hello,



\\\
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
///
 
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
 
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
 
Back
Top