My contemplations and diurnal novelties are publicized here

Archive for April 6, 2012

How to get checkboxlist ( values using jquery

In usually checkboxlist is binded with a data source and you need to check the checkboxes value sometime on client side.

How I approached this, attaching a class to list item for Checkboxlist using following code:-

foreach (ListItem li in checkBoxList.Items)        {

li.Attributes[“class”] = “checkBoxListItems”;


A checkboxlist in is usually rendered as


<input id=”ctl00_ContentPlaceHolder1_ checkBoxListItems_1″ type=”checkbox” name=”ctl00$ContentPlaceHolder1$checkBoxListItems$3″>

<label for=”ctl00_ContentPlaceHolder1_checkBoxListItems _3″>You label here</label>


So I used jquery to iterate through all the listitem and get the checked items using.

$(‘.btnCompareSelected’).click(function() {
var selectedCount = 0;
$(“. checkBoxListItems “).each(
function(intIndex) {
if ($(this).find(‘input’).attr(‘checked’) == true)
if (selectedCount < 2) {
alert(‘Atleast select 2 products to compare’);
return false;

%d bloggers like this: