How to get the checkbox checked value in the save click event and save it in the database
<p>I have checkbox in the gridview and a save button.....so far i have done to maintain the state of the checkbox in the pageindexchanging...in the save button click i want to save the values in which the checkbox is checked and save it in the database i need the code?</p>

<pre><code>protected void ManageCalenderShift_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    StoreOldValue();
    EmployeeDetails.PageIndex = e.NewPageIndex;
    BindDataToGrid();
    PupulateoldCheckValue();
}
private void StoreOldValue()
{
    ArrayList categoryIDList = new ArrayList();
    foreach (GridViewRow row in EmployeeDetails.Rows)
    {
        Label can_id = (Label)row.FindControl("UserACENumber");
        bool result = ((CheckBox)row.FindControl("Chkgrid")).Checked;

        // Check in the Session
        if (Session["CHECKED_ITEMS"] != null)
            categoryIDList = (ArrayList)Session["CHECKED_ITEMS"];
        if (result)
        {
            if (!categoryIDList.Contains(can_id.Text))
                categoryIDList.Add(can_id.Text);
        }
        else
            categoryIDList.Remove(can_id.Text);
    }
    if (categoryIDList != null &amp;&amp; categoryIDList.Count &gt; 0)
        Session["CHECKED_ITEMS"] = categoryIDList;
}
private void PupulateoldCheckValue()
{
    ArrayList categoryIDList = (ArrayList)Session["CHECKED_ITEMS"];
    if (categoryIDList != null &amp;&amp; categoryIDList.Count &gt; 0)
    {
        foreach (GridViewRow row in EmployeeDetails.Rows)
        {
            Label can_id = (Label)row.FindControl("UserACENumber");
            if (categoryIDList.Contains(can_id.Text))
            {
                CheckBox myCheckBox = (CheckBox)row.FindControl("Chkgrid");
                myCheckBox.Checked = true;
            }
        }
    }
}
</code></pre>

<p>in the save button click how to find the controls which is checked and save it in the database?</p>

<pre><code>protected void Save_Click(object sender, EventArgs e)
{


foreach (GridViewRow row in EmployeeDetails.Rows)
    {
        CheckBox chkGrid = (CheckBox)EmployeeDetails.Rows[i].FindControl("chkGrid");
        if (chkGrid.Checked == true)
        {
            //There are two pages and four records in that i have checked the four records but controlis finding for the first two records in the first page if i use this code....
        }
    }



}
</code></pre>
