Uncheck Checkboxes in GridView with Paging

4.7k Views Asked by At

I have an ASP .NET GridView with Paging. One column in it has a CheckBox. In a certain scenario, I want to uncheck the checkboxes that are checked.

foreach (GridViewRow dr in gvMyGridView.Rows)
{
    if (dr.RowType == DataControlRowType.DataRow)
    {
        if ((CheckBox)dr.FindControl("chkIsApplicable") != null)
        {
            ((CheckBox)dr.FindControl("chkIsApplicable")).Checked = false;
        }
    }
}  

But unfortunately because of Paging only the records that are currently shown in the Grid can be accessed in this way. I want it to apply to ALL the items in the GridView. This should happen client side and when the user commits will get saved to the database. Any way to handle this? :)

1

There are 1 best solutions below

0
On BEST ANSWER

Maintaining the State of Checkbox while Paging in Gridview

The Logic

Save the checked rows primary keys to a list at PageIndexChanging event.
After setting the grid to new PageIndex and re-binding the grid, populate the new page with values in the list that is mapped to the rows in grid(if any)
So you will have a collection of checked rows in a list.
Delete the list to clear all.

This is one way of doing it.
PS: Its a two year old post, so you can surely optimise it with C# 4.0