capiono
capiono

Reputation: 2997

Find all Check checkboxes in a asp.net GridView using Jquery

I need to loop over all the rows in a GridView and find all the checkboxes in the row. The GridVew has about 16 pages.

currently I'm using this script:

        function SelectAllCheckboxes(value) {
            $('#' + '<%=dgForms.ClientID%> tr' ).each(function () {
            $(this).find("td input[id*='chkCommon']:checkbox").prop('checked', value);
        });

This loops over only the current page rows. That is, if I'm on page 5, only the check boxes on that page will be selected.

How do I get all the rows from all 16 pages? I think I need to get it from the DOM but not sure how.

Upvotes: 1

Views: 827

Answers (3)

TheBeginner
TheBeginner

Reputation: 66

What you can do here is recreate the data source. Filter out all the ones that are not selected(which should be easy). Next bind the new grid containing only checked rows and display the same.

Not a very charming solution but should serve your need.

Upvotes: 0

Anibal D&#237;az
Anibal D&#237;az

Reputation: 111

The Gridview is a ASP.Net control. When you click over pagination, the gridview launch a postback for get data. Jquery is a framework for javascript. Javascript is a language that work on client browser. If you want select all checkbox controls, these controls must exist in the browser.

In short, the problem is not the jquery code but the technique used.

Upvotes: 2

Clint B
Clint B

Reputation: 4700

Only the current page is in the DOM. Pagination works by using AJAX (partial page updates) to download one page at a time to the browser. You will need to programmatically step through the pages.

Upvotes: 1

Related Questions