My code as follows
private void SaveCheckedValues()
{
System.Collections.ArrayList userdetails = new System.Collections.ArrayList();
int index = -1;
foreach (GridViewRow gvrow in grdRpt.Rows)
{
object o = grdRpt.DataKeys[gvrow.RowIndex].Value;
index = (int)0;
bool result = ((CheckBox)gvrow.FindControl("chkselecdata")).Checked;
if (Session["CHECKED_ITEMS"] != null)
userdetails = (System.Collections.ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!userdetails.Contains(index))
userdetails.Add(index);
}
else
userdetails.Remove(index);
}
if (userdetails != null && userdetails.Count > 0)
Session["CHECKED_ITEMS"] = userdetails;
}
when i run the above code shows error as follows
index was out of range.
Must be non-negative and less than the size of the collection parameter name 'Index'
The error show in below line as follows
object o = grdRpt.DataKeys[gvrow.RowIndex].Value;
In the gridview values as follows
transacteeid totalprice Qty Isactive
109453628727 25 1 1
109453628727 15 2 1
565676778 8 3 1
When i debug and check in the value i get value as "109453628727"
how to solve this error. what is the mistake in my above code.
What I have tried:
My code as follows
private void SaveCheckedValues()
{
System.Collections.ArrayList userdetails = new System.Collections.ArrayList();
int index = -1;
foreach (GridViewRow gvrow in grdRpt.Rows)
{
object o = grdRpt.DataKeys[gvrow.RowIndex].Value;
index = (int)0;
bool result = ((CheckBox)gvrow.FindControl("chkselecdata")).Checked;
// Check in the Session
if (Session["CHECKED_ITEMS"] != null)
userdetails = (System.Collections.ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!userdetails.Contains(index))
userdetails.Add(index);
}
else
userdetails.Remove(index);
}
if (userdetails != null && userdetails.Count > 0)
Session["CHECKED_ITEMS"] = userdetails;
}
when i run the above code shows error as follows
index was out of range.
Must be non-negative and less than the size of the collection parameter name 'Index'
The error show in below line as follows
object o = grdRpt.DataKeys[gvrow.RowIndex].Value;
In the gridview values as follows
transacteeid totalprice Qty Isactive
109453628727 25 1 1
109453628727 15 2 1
565676778 8 3 1
When i debug and check in the value i get value as "109453628727"
how to solve this error. what is the mistake in my above code.