Skip to content

Instantly share code, notes, and snippets.

@dannylloyd
Last active September 27, 2015 11:18
Show Gist options
  • Select an option

  • Save dannylloyd/1261600 to your computer and use it in GitHub Desktop.

Select an option

Save dannylloyd/1261600 to your computer and use it in GitHub Desktop.
Selects all checkboxes in a asp.net gridview
var gridView = '#<%= gridViewId.ClientID%>';
var checkAll = '#checkBoxId';
$(checkAll).click(function (i, v) {
$('input[type=checkbox]', gridView).prop('checked', this.checked);
});
var checkCount = $('input[type=checkbox]', gridView).length;
$('input[type=checkbox]', gridView).click(function (i, v) {
$(checkAll).prop('checked', $('input:checked', gridView).length == checkCount);
});
@dannylloyd
Copy link
Author

Revised the original one, this will select and deselect all checkboxes. If one of the gridview checkboxes is unchecked the select all will deselect itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment