开发者

Updating placeholder during runtime

开发者 https://www.devze.com 2022-12-22 11:32 出处:网络
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

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 开发者_StackOverflow社区= 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


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.


Try using a Panel instead of a PlaceHolder

0

精彩评论

暂无评论...
验证码 换一张
取 消