Hi Frndz,
Functionality :: store previous page checkbox checked value in gridview
Make two function
First for Remember Old Checkbox Value
Second for Repopulate Checkbox Old Checked value
private void RememberOldValues()
{
ArrayList categoryIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in grdAccDetails.Rows)
{
index = Convert.ToInt32(grdAccDetails.DataKeys[row.RowIndex].Value);
bool result = ((CheckBox)row.FindControl("chkList")).Checked;
// Check in the Session
if (Session["CHECKED_ITEMS"] != null)
categoryIDList = (ArrayList)Session["CHECKED_ITEMS"];
categoryIDList.Remove(index);
if (result)
{
categoryIDList.Add(index);
}
}
if (categoryIDList != null && categoryIDList.Count > 0)
Session["CHECKED_ITEMS"] = categoryIDList;
}
private void RePopulateValues()
{
ArrayList categoryIDList = (ArrayList)Session["CHECKED_ITEMS"];
if (categoryIDList != null && categoryIDList.Count > 0)
{
foreach (GridViewRow row in grdAccDetails.Rows)
{
int index = Convert.ToInt32(grdAccDetails.DataKeys[row.RowIndex].Value);
if (categoryIDList.Contains(index))
{
CheckBox myCheckBox = (CheckBox)row.FindControl("chkList");
myCheckBox.Checked = true;
}
}
}
}
Now call this function on Page Index Change Event
First Call RememberSaveValue After then bind grid, after then call Repopulate checked value on PageIndex Change.
protected void grdAccDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
RememberOldValues();
grdAccDetails.PageIndex = e.NewPageIndex;
DataTable dtMain = BINDDataTable();
grdAccDetails.DataSource = dtMain;
grdAccDetails.DataBind();
RePopulateValues();
}
Hope this helpful!
Thanks