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.Argument OutOfRangeExcep tion: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
Line 244: {
Line 245: // Retreive the Employee ID
Line 246: int RollNo = Convert.ToInt32 (GridView1.Data Keys[row.RowIndex].Value);
Line 247: // Pass the value of the selected RollNo to the Delete //Method.
Line 248: DeleteStudent(R ollNo);
This is my actual code
protected void Button2_Click(o bject sender, EventArgs e)
{
// Looping through all the rows in the GridView
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox checkbox1 = (CheckBox)row.F indControl("Che ckBox1");
//Check if the checkbox is checked.
//value in the HtmlInputCheckB ox's Value property is set as the //value of the delete method's parameter.
if (checkbox1.Chec ked)
{
// Retreive the Employee ID
int RollNo = Convert.ToInt32 (GridView1.Data Keys[row.RowIndex].Value);
// Pass the value of the selected RollNo to the Delete //Method.
DeleteStudent(R ollNo);
BindGrid();
}
}
}
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.Argument OutOfRangeExcep tion: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
Line 244: {
Line 245: // Retreive the Employee ID
Line 246: int RollNo = Convert.ToInt32 (GridView1.Data Keys[row.RowIndex].Value);
Line 247: // Pass the value of the selected RollNo to the Delete //Method.
Line 248: DeleteStudent(R ollNo);
This is my actual code
protected void Button2_Click(o bject sender, EventArgs e)
{
// Looping through all the rows in the GridView
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox checkbox1 = (CheckBox)row.F indControl("Che ckBox1");
//Check if the checkbox is checked.
//value in the HtmlInputCheckB ox's Value property is set as the //value of the delete method's parameter.
if (checkbox1.Chec ked)
{
// Retreive the Employee ID
int RollNo = Convert.ToInt32 (GridView1.Data Keys[row.RowIndex].Value);
// Pass the value of the selected RollNo to the Delete //Method.
DeleteStudent(R ollNo);
BindGrid();
}
}
}
Comment