Home > Asp.net > Create an Asp.net Gridview with Checkbox in each row

Create an Asp.net Gridview with Checkbox in each row

One of the frequent requirements for Asp.net Gridview is to add a checkbox for each row and a checkbox to select all the items like the Gridview below. This can be easily achieved by using jQuery. You can find the complete source code here.

$(document).ready(function () {

$(‘input[name$=”CDSelectAll”]’).click(function () {


if ($(this).attr(“checked”)) {

$(‘input[name$=”CDSelect”]’).attr(‘checked’, ‘checked’);

} else {

$(‘input[name$=”CDSelect”]’).removeAttr(‘checked’);

}

});

});


Updated 15 July 2011:

In the new release of  version 1.6.2 , it supports a new method called prop, you can use a new way to achieve the same thing as follow:

function ToggleAllCDs() {
$(‘input[name$=”CDSelectNew”]’).prop(“checked”, $(‘[name$=”CDSelectAllNew”]’).prop(“checked”));
}

$(document).ready(function () {
$(‘input[name$=”CDSelectAllNew”]’).click(ToggleAllCDs);
});

You can find the updated source code here.

Advertisements
Categories: Asp.net
  1. No comments yet.
  1. No trackbacks yet.

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: