Archive for August, 2012

Single selection Checkboxlist in with the help of JQUERY

August 2, 2012 5 comments

As we know CheckBoxList server control that comes under “System.Web.UI.WebControls” namespace allow multi selection . In this Small post I will show you how to make single selection in CheckBoxList server control using J Query.

HTML for Control
When Binding dynamically from database

<asp:CheckBoxList ID="chkTest" runat="server"

When it is static

<asp:CheckBoxList ID="chkTest" runat="server"
RepeatLayout=Flow  RepeatDirection="Horizontal" Width="99%">
<asp:ListItem Text="Test1" Value="1" Selected="True"></asp:ListItem>
<asp:ListItem Text="Test2" Value="2"></asp:ListItem>
<asp:ListItem Text="Test3" Value="3"></asp:ListItem>
<asp:ListItem Text="Test4" Value="4"></asp:ListItem>

JQuery for this

<script type="text/javascript">
$(document).ready(function() {
var checkboxes = $('#<%=chkTest.ClientID %>').find('input:checkbox'); {
var selectedIndex = checkboxes.index($(this));

var items = $('#<% = chkTest.ClientID %> input:checkbox');
for (i = 0; i < items.length; i++) {
if (i == selectedIndex)
items[i].checked = true;
items[i].checked = false;

I hope . you will find it helpfull.

Categories: ASP.NET, JQuery Tags: ,
%d bloggers like this: