aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to make single radio button selection in gridview using javascript

Dec 20, 2010

Here I will explain how to make single radio button selection in gridview using javascript.


In my application I have designed gridview with radio button after completion of all the functionality if try to select radio button I am able to select all the radio buttons in gridview that is like this 

My requirement is to make single radio button selection in gridview for that I have written JavaScript function to maintain single radio button selection in gridview. To implement this first design your aspx page like this 

<html xmlns="">
<head id="Head1" runat="server">
<title>Grdview with Arraylist</title>
<style type="text/css">
<script language="javascript" type="text/javascript">
function SelectSingleRadiobutton(rdbtnid) {
var rdBtn = document.getElementById(rdbtnid);
var rdBtnList = document.getElementsByTagName("input");
for (i = 0; i < rdBtnList.length; i++) {
if (rdBtnList[i].type == "radio" && rdBtnList[i].id !=
rdBtnList[i].checked = false;
<form id="form1" runat="server">
<asp:GridView ID="gvdata" runat="server" CssClass="Gridview" AutoGenerateColumns="false" DataKeyNames="UserId" HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White">
<asp:RadioButton id="rdbUser" runat="server" OnClick="javascript:SelectSingleRadiobutton(" />
<asp:BoundField DataField="UserName" HeaderText="Name"/>
<asp:BoundField DataField ="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Location" HeaderText="Location" />

In code behind bind your gridview and check it 

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
protected void BindGridviewData()
SqlConnection con = new SqlConnection("Data Source=MYSystem;Initial Catalog=MySamplesDB;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select UserId,UserName,FirstName,LastName,Location from User_Information", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
gvdata.DataSource = ds;


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

Very useful blog...Thanks to the Author

Anonymous said...

thank u so much....this is really useful......

SKKO said...

I also using radio selection on Gridview.
My radio button selection is also working for single selection.
now what I want to know is:
when I selected one radio button,
I want GridView SelectIndex chaging event occurs
like Select Command.
can I use?
if like Select Command, I can easily call like
GridView1.SelectedRow. ..etc..
but now I cannot use like that
I just lopping GridView rows if radio is selected or not.
do u have any refreences?

Rishikesha said...

thank u so much....this is really useful......

Anonymous said...

thank u so much

Anonymous said...

Thank you Suresh Dasari, this post Helped me a lot :)

Unknown said...

how to show selected value in lable using gridview radio button

shekar said...

Thank you Suresh Dasari, this code is Helped me a lot. Thank you very much.

Anonymous said...

Thanks ... it is a very important piece of code


Anonymous said...

it's not working in radiobuttonlist

Unknown said...

thanks for this
but m find out in a grid view two columns use radio button if m apply this code then both two columns buttons are treated as same
bt i want to seprate column and i want to aaply in both column different code

Bharat Gunjal said...


Anonymous said...

thank u

Anonymous said...


RS Prajapati said...

in really helpful.perfect working

Praveen said...

Really this is very good code

Unknown said...

It is good..
Could you tell
how to get the row details of datagridview on selection of radio button.

Anonymous said...

Thank you

Anonymous said...

Thank you, it works.

Anonymous said...

Great example....Thanks...!!!


Unknown said...

very useful information!!!!! valuable posts from you.

Anonymous said...

Thanks alot

Unknown said...

thanks it work..but now want to retrieve selected value on button click

Nam said...

Really very helpful saved my day thanks a ton

Unknown said...


Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.