I have a repeater and inside the repeater a radiobutton control, in code behind I fill the groupname for the radiobutton control, so, when I run it, I have a table with many rows and some of them have radiobutton:
<asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" ViewStateMode="Enabled">
<HeaderTemplate>
<table class="table table-responsive table-bordered ">
<tr class="text-center" style="background-color: #6e6259; color: white;">
<th class="text-center">DESCRIPTION</th>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="padding-left: 20px;">
<asp:RadioButton ID="rbtDinamic" OnCheckedChanged="rbtDinamic_CheckedChanged" AutoPostBack="true"
ViewStateMode="Enabled" Visible="false" GroupName='<%#Eval("groupvalue") %>' runat="server"/></td>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
And in the itemdatabound of repeater I fill the value for groupname:
Private Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Try
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
If CType(e.Item.FindControl("hdf1"), Label).Text = False Then
CType(e.Item.FindControl("rbtDinamic"), RadioButton).Visible = True
CType(e.Item.FindControl("rbtDinamic"), RadioButton).GroupName = CType(e.Item.FindControl("groupvalue"), Label).Text = False
End If
End If
Catch ex As Exception
End Try
End Sub
But when I run it the repeater creates the group name with diferent names:
Radiobutton row 1:
Repeater1$ctl05$1
Radiobutton row 2:
Repeater1$ctl06$1
So it let checked all the radiobuttons, instead to uncheck when another one for the same group is cheked.
I find this code in a forum, but it work only if I have only one groupname, but I can have more than one groupname:
Protected Sub rbtDinamic_CheckedChanged(sender As Object, e As EventArgs)
For Each item As RepeaterItem In Repeater1.Items
Dim rbtn As RadioButton = DirectCast(item.FindControl("rbtDinamic"), RadioButton)
rbtn.Checked = False
Next
DirectCast(sender, RadioButton).Checked = True
End Sub
But there can be more than one group of radiobuttons, so in this case I can't use this code.
Is there anywhere to do this? thanks