Parsing a label collection problem

P

Pumkin

Hey guys,
It appears to be a very simple problem, but I just cannot realize why
it is happening.


I have a HTMLTable in which I put 10 labels. Now, I'm trying to parse
the collection and to put text on labels.
Here is my code :


Dim ctrlLbl As Control
For Each ctrlLbl In Me.Controls
If (TypeOf (ctrlLbl) Is UI.WebControls.Label) Then
CType(ctrlLbl, Label).Text = "something"
k += 1
End If
Next


The problem is that there are no labels in the ControlCollection thus
there are 10 in the table on the page.
I tried to parse the table collection but with the same result.
Can anybody explain me what is happening there?
Thank you in advance
 
G

gellis99

I ran into this problem sometime back...it's pretty straightforward.
The issue is that the label controls are child controls of the table
control. In other words, Me.Controls would have a table control, and
the table would have the label controls. I got around this issue in
this issue by creating a function that accepted a control and called
itself recursively if the control had child controls. If the control
was of a certain type, I set various properties. At the end of the sub
it checked to see if there were child controls and, if so, call itself
passing the child control. It would look something like this...

function SetTheText(Page as Control)
Dim ctrlMe as control
for each ctrlMe in page
if typeof(ctrlMe) is label then
ctype(ctrlMe).text = "something"
end if
if ctlcontrol.controls.count > 0 then
SetTheText(ctrlme) 'this recursive call will dig into
your table's controls
end if
next
end function

It's been a while since I worked through this, but you should be able
to follow the example above and make some progress.
 
P

Pumkin

Thanks a lot... It's a great idea making a recursive function for it.
I'm now developing a little bit for the case I need.
Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top