Topic: How to enable a Radio Button Group inside a repeater with JavaScript
Share/Save/Bookmark
Description: This code allows you to treat radio buttons inside a repeater as a group.  This is needed because Microsoft's repeater control implements the INamingContainer making each control unique.  The GroupName attribute will not work because the unique client naming overrides the use of the GroupName property.  The Javascript below basically unchecks the radio buttons that are not selected.


1.  On the ItemDataBound event add the follwoing line:     rdoMyBatch.Attributes.Add("onclick", "SetUniqueRadioButton('rptLabels.*rdoMyBatchIdentifier', this)")
2.  Add the following JavaScript to your page or inside a Javascript code behind file.     function SetUniqueRadioButton(nameregex, current)
     {
        re = new RegExp(nameregex);
        
        for(i = 0; i < document.formss[0].elements.length; i++)
        {
           elm = document.forms[0].elements[i];

           if(elm.type == 'radio')
           {
              if (re.test(elm.name))
              {
                  elm.checked = false;
              }
           }
        }
        current.checked = true;
     }