views:

69

answers:

2

Hi Everyone, here is the problem I am having with placeholder:

I have a repeater and within that repeater, I have an item template. Now this template is formatted with a couple of tables, but for this question I have removed them to make things easier to read:

<asp:Repeater ID="Repeater1" OnItemDataBound="R1_ItemDataBound" runat="server">

   <ItemTemplate>
      <asp:PlaceHolder ID="phAnswers" runat="server"></asp:PlaceHolder>               
   </ItemTemplate>
</asp:Repeater>

Then, on the event OnItemDataBound, I create a new placeholder, bind it to the existing on (phAnswers), however the placeholder is not updated with the radiobuttons/textboxs that are created:

    Dim rdList As New RadioButtonList
    Dim newRadio As New RadioButton

 If (e.Item.ItemType = ListItemType.Item) Or _
        (e.Item.ItemType = ListItemType.AlternatingItem) Then

        Dim tempPH As PlaceHolder

        tempPH = e.Item.FindControl("phAnswers")

        For x As Integer = 0 To (t_MC.Count - 1)

                newRadio = New RadioButton

                newRadio.ID = "Answer" + x.ToString
                newRadio.Text = t_MC(x).Value
                rdList.Controls.Add(newRadio)

            Next

   tempPH.Controls.Add(rdList)

Any ideas why phAnswers is not updated with the new tempPH placeholder? Cheers

A: 

Try using a Panel instead of a PlaceHolder

used2could
Actually, I have tried using a Panel and I get the same results
AllStar11
A: 

OnItemDataBound may be too late to add controls. Try it in OnItemCreated and see if that helps. It's a quick test - just change your repeater event declaration like this:

OnItemCreated="R1_ItemDataBound"

If this idea doesn't help, you can easily switch it back.

Edit - I just noticed something. To populate a RadioButtonList, you should use ListItems, like this:

ListItem item - new ListItem("your text", "your value");
rdList.Items.Add(item);

This is probably why your RadioButtonList did not appear, but lone radio buttons worked.

Ray
No luck with this. Any other ideas?
AllStar11
sure - just edited my answer.
Ray
Yeah...figures it was something silly like that. Thanks a lot, I appreciate it.
AllStar11