Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How we can group radio buttons inside a repeater?

Tags:

asp.net

I have a radio button inside a repeater as follow.

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

Now problem is that how I can select a single radio button across multiples. Even though I have given a groupname for radio button, I am not able to select any of them.

like image 743
Rajbir Singh Avatar asked Jan 19 '12 11:01

Rajbir Singh


2 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 on click of radiobutton

onclick="fnCheckUnCheck(this.id);"
like image 197
Pankaj Avatar answered Nov 09 '22 14:11

Pankaj


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

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

got the solution from Radio button repeater problem solved

like image 38
Sebastien H. Avatar answered Nov 09 '22 13:11

Sebastien H.