Here I have created sample that will help you out.
HTML
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function RadioCheck(rb) {
var gv = document.getElementById("<%=GridView1.ClientID%>");
var rbs = gv.getElementsByTagName("input");
var row = rb.parentNode.parentNode;
var types = gv.getElementsByTagName("span");
var type = row.getElementsByTagName("span");
for (var i = 0; i < rbs.length; i++) {
if (type[0].innerHTML == types[i].innerHTML) {
if (rbs[i].type == "radio") {
if (rbs[i].checked && rbs[i] != rb && types[i] != type) {
rbs[i].checked = false;
break;
}
}
}
}
}
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Font-Names="Arial"
Font-Size="11pt" AllowPaging="false" PageSize="3">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="150" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" onclick="RadioCheck(this);" />
<%--<input id="hfType" type="hidden" value='<%#Eval("Type") %>' />--%>
<asp:Label ID="lblType" Text='<%#Eval("Type") %>' runat="server" Style="display: none" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button Text="Submit" runat="server" OnClick="btn_Submit_Click" />
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)),new DataColumn("Type",typeof(string)) });
dt.Rows.Add(1, "David", "UK", "0");
dt.Rows.Add(2, "Jhon", "USA", "0");
dt.Rows.Add(3, "Kevin", "USA", "0");
dt.Rows.Add(4, "Peter", "UK", "1");
dt.Rows.Add(5, "Andrea", "USA", "1");
dt.Rows.Add(6, "Anabell", "UAE", "2");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void btn_Submit_Click(object sender, EventArgs e)
{
foreach (GridViewRow GVR in GridView1.Rows)
{
RadioButton RadioButton1 = (RadioButton)GridView1.Rows[GVR.RowIndex].FindControl("RadioButton1");
if (RadioButton1.Checked == true)
{
string ID = GridView1.Rows[GVR.RowIndex].Cells[0].Text;
string Type = ((Label)GridView1.Rows[GVR.RowIndex].FindControl("lblType")).Text;
}
}
}
In below screenshot you can see,first three records are type of 0 and next two records are type of 1 and last record is type of 2,hence we can select only one radiobutton of first three records and so on.
Screenshot
