How to keep checkbox state in gridview while paging?

G

Guest

Is it possible to use session by cast it to an array to keep gridview primary
key?
I have the following code in place, but it gives me error saying "Unable to
cast object of type 'System.String' to type 'System.Collections.ArrayList".
Please help...

private void StoreCheckedItems()
{
ArrayList reasonIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in gvReason.Rows)
{
index = (int)gvReason.DataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row.FindControl("chkReason")).Checked;
if (Session[CHECKED_ITEMS] != null)
reasonIDList = (ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!reasonIDList.Contains(index))
reasonIDList.Add(index);
}
else
reasonIDList.Remove(index);
}

Thanks!

Sophie
 
D

Dave Sexton

Hi Sophie,

What does the code look like that assigns Session["CHECKED_ITEMS"]?

I assume that it's being assigned to a string, hence the error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top