0

I have a Repeater of RadioButton. Is there an easy way to access all these RadioButton from the C# side? For example, maybe access by the GroupName? I couldn't find anything simple online.

ASPX:

<asp:Repeater ID="rptOtherNetworks" runat="server" >
    <HeaderTemplate>
        <li data-theme="c" data-role="list-divider" class="ui-li ui-li-divider ui-bar-b">
            <asp:Localize ID="locRecentlySelected" runat="server"
                EnableViewState="False" meta:resourcekey="locRecentlySelectedResource1"
                Text="Select Network from Other Cameras">
            </asp:Localize>
        </li>
    </HeaderTemplate>
    <ItemTemplate>
        <li data-theme="c">
            <!-- I want to access these -->
            <asp:RadioButton Text='<%# Eval("NetworkDescription") %>' data-mac='<%# Eval("MAC") %>'
                Checked="False" GroupName="RadioGroupNetworkCameras" runat="server" />
        </li>
    </ItemTemplate>
</asp:Repeater>

1 Answers1

0

Well, you can retrieve all of the RadioButtons by finding them by their ID in each of the RepeaterItems.

<asp:RadioButton ID="rb"
    Text='<%# Eval("NetworkDescription") %>'
    data-mac='<%# Eval("MAC") %>'
    Checked="False"
    GroupName="RadioGroupNetworkCameras"
    runat="server" />
foreach (RepeaterItem ri in rptOtherNetworks.Items)
{
    if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
    {
        RadioButton r = (RadioButton)ri.FindControl("rb");
    }
}

But a problem you are going to run into is that within the Repeater, the radio buttons will not be mutually exclusive. There are various ways of "fixing" this through JavaScript and other methods, but just be aware this.

Community
  • 1
  • 1
j.f.
  • 3,908
  • 2
  • 29
  • 42