How to make single radio button selection in gridview using javascript In Asp.net

How to make single radio button selection in gridview using javascript In Asp.net

The Following Is html for your aspx page

In above Page you can see javascript function CheckOtherIsCheckedByGVID that is call on radio button on click that allow only

single radio button selection in gridview

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function CheckOtherIsCheckedByGVID(spanChk) {
            var IsChecked = spanChk.checked;
            if (IsChecked) {

            var CurrentRdbID = spanChk.id;
            var Chk = spanChk;
            Parent = document.getElementById("<%=GridView1.ClientID%>");
            var items = Parent.getElementsByTagName('input');
            for (i = 0; i < items.length; i++) {
                if (items[i].id != CurrentRdbID && items[i].type == "radio") {
                    if (items[i].checked) {
                        items[i].checked = false;
                        items[i].parentElement.parentElement.style.backgroundColor = 'white'

                        items[i].parentElement.parentElement.style.color = 'black';
    <form id="form1" runat="server">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <asp:TemplateField HeaderText="Primary" ItemStyle-Width="50px">
                            <asp:RadioButton ID="rbowner" runat="server" Checked='<%#Eval("Contact_Primary").ToString().Equals("True")%>' onclick="javascript:CheckOtherIsCheckedByGVID(this);" />
                    <asp:TemplateField HeaderText="Primary" ItemStyle-Width="50px">
                    <asp:TemplateField HeaderText="Primary" ItemStyle-Width="50px">

The Following is Code Behind For your Default.Vb Page

The Below code fill gridview on page Load

Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim dt As New DataTable()
        dt.Columns.AddRange(New DataColumn() {New DataColumn("contactname", GetType(String)), _
                                                        New DataColumn("email", GetType(String)), _
                                                        New DataColumn("Contact_Primary", GetType(Boolean
        dt.Rows.Add("Shahid", "[email protected]", True)
        dt.Rows.Add("Karib", "[email protected]", False)
        dt.Rows.Add("Vineet", "[email protected]", False)
        GridView1.DataSource = dt
    End Sub
End Class