0
votes

I need to "check" all of the checkboxes in an asp.net gridview. I can do so with code-behind but would rather do this on the client side with jquery. The column that the checkbox is stored in is called "displayButton" because it displays another action button once a checkbox is checked.

Not sure how to begin here.

5
your rendered html would help.. (if it's readable... (asp.net)) - jondavidjohn

5 Answers

2
votes

You would start with a selector that selects all the checkboxes that you want to check, then use the prop() function to change their 'checked' properties to true:

$('input:checkbox').not(':checked').prop('checked', true);

Note: Check mblase75's response for jQuery version issues.

--UPDATE--

I ran a jsperf and not checking if the checkbox is already checked is quite a lot slower (approximately 50% slower) than just using the .prop() function to set all checkboxe's checked property to true.

1
votes

$("input:checkbox").prop("checked",true)

or $("input:checkbox").attr("checked","checked") for jQuery 1.5.x or earlier.

That said: you say you would rather not do this in ASP.Net, but if it's at all possible your users will have JavaScript turned off, you'll have to do it server-side.

1
votes

for jquery lower than 1.6

$('input:checkbox').attr('checked', "checked");

and for 1.6+

$('input:checkbox').prop('checked', true);
0
votes
$("#id input:checkbox").prop("checked", true);

or

$(".class input:checkbox").prop("checked", true);
-1
votes
$('#girdid input [type="checkbox"]').attr('checked', true);

this is solution. I hope it helps