getting controls from the placeholder controls collection

  • Thread starter msnews.microsoft.com
  • 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
 
G

Guest

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
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top