Export selected rows of gridview to Excel or word in ASP.Net By Using 3-Tier Architecture

Posted by Priyatham under .NET Certifications on 7/2/2013 | Points: 10 | Views : 1425 | Status : [Member] | Replies : 1
private void SaveCheckedValues()
{
ArrayList userdetails = new ArrayList();
int index = -1;
foreach (GridViewRow gvrow in gvdetails.Rows)
{
index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;
bool result = ((CheckBox)gvrow.FindControl("chkSelect")).Checked;
// Check in the Session
if (ViewState["CHECKED_ITEMS"] != null)
userdetails = (ArrayList)ViewState["CHECKED_ITEMS"];
if (result)
{
if (!userdetails.Contains(index))
userdetails.Add(index);
}
else
userdetails.Remove(index);
}
if (userdetails != null && userdetails.Count > 0)
ViewState["CHECKED_ITEMS"] = userdetails;
}
Can any one help me out of this excepiton from the above code
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

M.priyatham


Responses

Posted by: Jitendrasoft09 on: 7/2/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Pritam,

You mention your index value as following code-
int index=0;
or
int index;

Hope you are clear.

Jitendra Kumar
If my post helps you, plz mark as an answer.

Priyatham, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response