Search code examples
jquerycheckboxgridviewpagination

Find the status of Checkbox in Grdiview with paging


This is the code that i use to find whether any checkbox is checked in gridview

 if($("table tr td:first-child input:checkbox:checked").length ==0)
 {
     alert("Select atleast one event to delete");return false ;
 }

 if(confirm('Are you sure! you want to delete the selected events(s)?'))
     return true;
 else
     return false ;

i select a checkbox in the first page and i navigate to the 2nd page and i click "Delete", it throws "select atleast one Channel to delete". Which Shouldn't!

Without paging it works fine. Any insight to implement this with paging?


Solution

  • As soon as you navigate to the next page the DOM elements for the checkboxes selected first are not displayed anymore, and therefore the script will not know about them.

    You will need to cache the state at a page change if you wish to preserve the checkbox state through pages. Remember that these won't be passed in a postback either.