i am using gridview. and i have a checkbox as a template column in gridview . when i checked single record and press delete button, then record is successfully perform delete. but when i check multiple record and click the delete then it gives following error:
Parameter name: index
Server Error in '/' Application.
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
CSS |
i am using below code to perform delete operation i am developing application in three-tire architecture.
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow objData in gvEmployee.Rows)
{
CheckBox chkBox = (CheckBox)objData.FindControl("chkDelete");
if (chkBox.Checked)
{
int id = Convert.ToInt32(gvEmployee.DataKeys[objData.RowIndex].Value.ToString());
objB.Delete(id);
fillEmployeeDetail();
}
}
}
can anyone give me solution. with code in asp.net,C#

Blocked AccountRank #403 · 6.2K reputationPosted Oct 9, 2008, 8:48 PM EDT
Hi,
try this
protected void btnDelete_Click(object sender, EventArgs e)
{
for (int index = 0; index <= gvEmployee.Rows.Count - 1; index++)
{
CheckBox chkBox = (CheckBox)gvEmployee.Rows(index).FindControl("chkDelete");
if (chkBox.Checked)
{
int id = Convert.ToInt32(gvEmployee.DataKeys[index].Value.ToString());
// Write the delete method here
fillEmployeeDetail();
}
}
}