getting controls from the placeholder controls collection

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

I'm adding multiple web controls to the placeholder controls collection, but
even when doing the for each and recursion method of getting the web
controls, I'm only getting the first web control that was added, and none of
the others. I've tried add and addat methods when adding the controls, but
while they appear on the form, only the first one can be retrieved. Is there
some better documentation anyone could send me?

-Max
 
Hi Max, the following should work:

Dim c As Control
Dim sb As New System.Text.StringBuilder
For Each c In PlaceHolder1.Controls()
sb.Append(c.ID)
sb.Append("<br>")
Next
Response.Write(sb.ToString())
This code just references each child in the placeholder's control collection
and grabs its id.. but you should be able to manipulate the child controls in
whatever way you like inside the for/each statement.
ie: lets say the 2nd control on the placeholder's collection was a Listbox..
and you wanted to add an item to the listboxe's items collection .. you could
do that inside the for each statement by doing this:

Dim c As Control
For Each c In PlaceHolder1.Controls()
If TypeOf (c) Is ListBox Then
CType(c, ListBox).Items.Add("New Item")
End If
Next

Thanks,
-Chris
 
Back
Top