Grid View checkbox view state
<p>iam using grid view in that 1st col is checboxes.and i want to maintain state..so iam using 2 functions </p>

<pre><code>private void RememberOldGridValues()
{
    ArrayList oUserCheckedList = new ArrayList();
    int index = -1;
    foreach (GridViewRow row in gridViewResults.Rows)
    {
        if (((CheckBox)row.FindControl("chkSelect")).Checked)
        {
            index = row.RowIndex;
            if (Session["CHECKED_ITEMS"] != null)
                oUserCheckedList = (ArrayList)Session["CHECKED_ITEMS"];
            if (oUserCheckedList.Count == 1)
            {
                oUserCheckedList.RemoveAt(0);
            }
                if (!oUserCheckedList.Contains(index))
                   oUserCheckedList.Add(index);                  
        }
        if (index &gt;= 0)
            break;              
    }
    if (oUserCheckedList != null &amp;&amp; oUserCheckedList.Count &gt; 0)
        Session["CHECKED_ITEMS"] = oUserCheckedList;
}
</code></pre>

<p>this is to rememeber checked values and other is repopulate vales which gets repopulated once u come back from other pages .. in this my adding index is 3 but when i retrive on main page coming form other pages to my suprise arraylist has count 1 but always point to 0 inderx so instaed my 5row.index it is shwoing me 0 row.index and be default selecte first checkbox.
this is code to repopulate values </p>

<pre><code>//to Repopulate Grid view Checkboxes
private void RePopulateGridValues()
{
    ArrayList oUserCheckedList = (ArrayList)Session["CHECKED_ITEMS"];
    if (oUserCheckedList != null &amp;&amp; oUserCheckedList.Count &gt; 0)
    {
        foreach (GridViewRow row in gridViewResults.Rows)
        {
            string str = oUserCheckedList[0].ToString();
            int i = Convert.ToInt32(str);
            if (row.RowIndex == i)
            {
                CheckBox myCheckBox = (CheckBox)row.FindControl("chkSelect");
                myCheckBox.Checked = true;
            }
        }
   }
</code></pre>

<p>any help will be appreciated.</p>
