0

I am using a nester repeater to dynamically build a list of radio buttons in a table:

 <ItemTemplate>
                 <tr>
                     <td>
                        <asp:Label ID="lblAccID" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                     </td>
                     <td>
                        <asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                     </td>
                     <td>  
                            <%-- POPULATE CONDITION RADIO BUTTONS --%>
                            <asp:Repeater ID="rpConditionRadioButtons" runat="server">
                                <ItemTemplate>
                                    <td>
                                        <asp:RadioButton ID="rbCondition" GroupName="gCondition" Text="" runat="server" />
                                    </td>
                                </ItemTemplate>
                            </asp:Repeater>
                     </td>
                </tr>
            </ItemTemplate>

But I can't figure out how to group them together. (Because the table is built on the fly I don't think I can use a radio button list.)

I have tried using the GroupName attribute, and setting the ClientIDMode to Static, but this didn't help.

Xordal
  • 1,369
  • 13
  • 29
Ben
  • 4,281
  • 8
  • 62
  • 103
  • I'm getting the opposite problem - rather than all the radio buttons being in group across all the rows in the repeater, they are operating independently. – Ben Jun 18 '13 at 08:09

1 Answers1

0

If you nest a repeater you have also a parent RepeaterItem with an unique identifier(e.g. a primary key). You can append that to the GroupName property dynamically in ItemDataBound of the inner repeater. You can access the outer repeater's current RepeaterItem from the inner repeater's ItemDataBound in the following way (assuming that lblAccID.Text contains the ID) :

protected void rpConditionRadioButtons_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Repeater innerRepeater = (Repeater)sender;
        RepeaterItem outerItem = (RepeaterItem)innerRepeater.NamingContainer;
        Label lblAccID = (Label)outerItem.FindControl("lblAccID");
        RadioButton rbCondition = (RadioButton) e.Item.FindControl("rbCondition");
        rbCondition.GroupName = "gCondition_" + lblAccID.Text;
    }
}

Comments:

OK - Found the radio buttons, and can change their attributes, but they still work independently.

I'm afraid this is a known bug.

Have a look at this question for further assistance: asp.net radio button grouping

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • @Ben: But `rpConditionRadioButtons_ItemDataBound` is triggered correctly for your inner repeater, have you used the debugger? – Tim Schmelter Jun 18 '13 at 08:36
  • OK - Found the radio buttons, and can change their attributes, but they still work independently. – Ben Jun 18 '13 at 08:40
  • @Ben: I'm afraid this is a known bug: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q316495 Have a look at this question for further assistance: http://stackoverflow.com/questions/1334926/asp-net-radio-button-grouping – Tim Schmelter Jun 18 '13 at 08:42