1

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.

2
  • from DOM it is not possible as when you click next of gridview paging then it binds data to grid means then it generates html but you can do via coding store all you value in a table then using Lambda query you can do this. Commented May 13, 2016 at 12:04
  • To do this from the DOM you'd have to render all the rows to the browser, which means disabling paging and rebinding. What is it you are actually trying to accomplish? XY Problem Commented May 13, 2016 at 16:38

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Clint: GridViews do not implement AJAX for paging.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.