My contemplations and diurnal novelties are publicized here


In asp.net 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 asp.net is usually rendered as

<span>

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

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

</span>

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)
selectedCount++;
});
if (selectedCount < 2) {
alert(‘Atleast select 2 products to compare’);
return false;
}
});

Advertisements

Comments on: "How to get checkboxlist (Asp.net) values using jquery" (2)

  1. Can’t seem to get it to work, though it looks like it should. I have checked items and none of them show as being checked.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: