Selected Value of ASP.NET RadioButtonList using jQuery

In this post, we will see how to display the text and value of the selected ASP.NET Radio Button.

A RadioButtonList control is declared in your WebForm like this: radiobutton

and gets rendered in the browser as radiobutton

Here’s the jQuery code to fetch the selected radiobutton text and value

<head runat="server">
title>Text and Value of the selected RadioButton</title>
script type="text/javascript" src="">
script type="text/javascript">
$(function () {
var $radBtn = $("table.tbl input:radio");
$ () {
var $radChecked = $(':radio:checked');
.append("<b>Index: </b>" +
$radChecked.val() + "<br/>")
.append("<b>Value: </b>" +

In the code shown above, we first retrieve the radio buttons using

var $radBtn = $("table.tbl input:radio");

An ASP.NET RadioButtonList gets rendered as a table. When the user clicks on any of the radio buttons, we are storing the radiobutton which was checked in the $radChecked variable. This is done to improve selector performance as shown below:

var $radChecked = $(':radio:checked');

We then use $radChecked.val() to retrieve the checked radiobutton ‘value’ and $ to retrieve the ‘text’.

Observe how we are accessing the value of a radiobutton using $ This is because a RadioButton gets rendered like this:


<input id="rbl_0" type="radio" name="rbl" value="0" />

<label for="rbl_0"></label>


To access the value, which is inside the label, we use next() which finds the very next sibling of each Radiobutton, which in our case, is the label control. The value and text is displayed on the page using a paragraph. The output looks similar to the one shown below:


See a Live Demo

There are plenty of similar recipes that I have covered in my EBook 51 Recipes using jQuery with ASP.NET Controls.

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: