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:
Line 244: {
Line 245: // Retreive the Employee ID
Line 246: int RollNo = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
Line 247: // Pass the value of the selected RollNo to the Delete //Method.
Line 248: DeleteStudent(RollNo);
This is the actual code
protected void Button2_Click(object sender, EventArgs e)
{
// Looping through all the rows in the GridView
//for (int i = 0; i <= GridView1.Rows.Count; i++)
//{
//GridViewRow row = GridView1.Rows[i];
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox checkbox1 = (CheckBox)row.FindControl("CheckBox1");
//Check if the checkbox is checked.
//value in the HtmlInputCheckBox's Value property is set as the //value of the delete method's parameter.
if (checkbox1.Checked)
{
// Retreive the Employee ID
int RollNo = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
// Pass the value of the selected RollNo to the Delete //Method.
DeleteStudent(RollNo);
BindGrid();
Bookmarks