How can we group radio buttons inside a repeater?

I have a switch in the repeater as shown below.

<asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <asp:RadioButton ID="rbtnCityName" runat="server" Text='<%# Bind("CityName") %>' GroupName="Cities" /> </ItemTemplate> </asp:Repeater> 

Now the problem is that I can choose one radio button from several multiple. Although I gave the group name for the switch, I cannot select any of them.

+4
source share
3 answers
 <script type="text/javascript" language="javascript"> function fnCheckUnCheck(objId) { var grd = document.getElementById("<%= rpt.ClientID %>"); //Collect A var rdoArray = grd.getElementsByTagName("input"); for(i=0;i<=rdoArray.length-1;i++) { if(rdoArray[i].type == 'radio') { if(rdoArray[i].id != objId) { rdoArray[i].checked = false; } } } } </script> 

call this function when you click a radio book

 onclick="fnCheckUnCheck(this.id);" 
+2
source

The best solution for me was to simply create an html input control inside the repeater:

  <input type="radio" name="yourGroup" value='<%# Eval("Value") %>'/> 

got a solution from a problem with a repeater of a radio channel is solved

+1
source
 $('#SubmitAnswers').click(function () { var names = []; $('input[type="radio"]').each(function () { // Creates an array with the names of all the different checkbox group. names[$(this).attr('name')] = true; }); // Goes through all the names and make sure there at least one checked. for (name in names) { var radio_buttons = $("input[name='" + name + "']"); if (radio_buttons.filter(':checked').length == 0) { // alert('none checked in ' + name); $('#Group'+ name).css("visibility", "visible"); } else { // If you need to use the result you can do so without // another (costly) jQuery selector call: var val = radio_buttons.val(); $('#Group' + name).css("visibility", "hidden"); } } }); 
0
source

Source: https://habr.com/ru/post/1391820/


All Articles