How select one radio button from multiple radio button in gridview


If you want to placed a radio button in gridview as selecting one out of more then one radio button, so use my resources. In this resources user can select single radio button option out of multiple radio button from gridview control using by javascript. No need for define group name in radio button.

Create a test.aspx page.

On test.aspx page



Paste below javascript on .aspx page.


function CheckOnOff(rdoId,grid)
{
var rdo = document.getElementById(rdoId);
var all = document.getElementsByTagName("input");
for(i=0;i {
if(all[i].type=="radio" && all[i].id != rdo.id)
{
var count=all[i].id.indexOf(grid);
if(count!=-1)
{
all[i].checked=false;
}
}
}
rdo.checked=true;/* Finally making the clicked radio button CHECKED */
}


Now set a gridview on body section of aspx page and placed a radio button control in TemplateField.
set the following properties of a radio button in a Gridview, to allow this script run properly. as following:

<asp:GridView ID="myGrid" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:RadioButton id="rdobutton" runat="server" OnClick="javascript:CheckOnOff(this.id,'grid_FreeGifts');"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


Now User can select only one radio button option from multiple option.


Thanks and Regards
Varun Bansal


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: