Reputation: 51
I have created repeater with radiobutton inside and binding data from db, all works good instead css and groupName.. when render - it doesn't works, user can check all radiobuttons instead one... This is my code below, please help...
<asp:Repeater ID="rptList" runat="server">
<ItemTemplate>
<ul><li>
<asp:RadioButton ID="RadioButton8"
runat="server"
CssClass="w1"
GroupName="Options"
Text='<%# DataBinder.Eval(Container.DataItem, "EvName")%>'
ValidationGroup="Options" />
</li></ul>
</ItemTemplate>
</asp:Repeater>
Upvotes: 3
Views: 4900
Reputation: 956
I had the same problem. I couldn't find a way that doesn't use jquery.
I was able to use this tutorial to solve my problem. http://blog.marketnet.com/index.php/2010/03/01/overcoming-the-radio-button-repeater-bug/
Copied from the tutorial:
In the markup file, add this bit of Javascript and jQuery:
<script type="text/javascript" language="javascript">
function SetUniqueRadioButton(strGroupName, current)
{
$("input[name$='" + strGroupName + "']").attr('checked', false);
current.checked = true;
}
</script>
Set up the Repeater control using a RadioButton control:
<asp:Repeater ID="rptMyRepeater" runat="server">
<ItemTemplate>
<asp:RadioButton ID="rdoButton" GroupName="GroupName" runat="server"/>
</ItemTemplate>
</asp:Repeater>
Finally, in the code behind file:
rdoButton.Attributes.Add("onclick", "SetUniqueRadioButton('MyGroupName',this)");
Upvotes: 2