Specified argument was out of the range of valid values.

Mr_Shaw
Mr_Shaw used Ask the Experts™
on
I am trying to delete a record from my gridview. My code is:

protected void edit_record_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

delete_record_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
        delete_record_method.Stored_Procedure_Name = "dbo.removed";
        delete_record_method.removed();
        BindData();
    }

I am getting an error which reads:

Specified argument was out of the range of valid values.
Parameter name: index

I am not sure how to fix this.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hello

delete_record_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex-1].Cells[2].Controls[0]).Text.ToString();



Just trying to help.



Great is our GOD.
:)

Author

Commented:
I tried changing the code to read

delete_record_method.Record_ID = ((TextBox)user_records.Rows[e.RowIndex-1].Cells[2].Controls[0]).Text.ToString();

I still get the same problem.

I just don't understand why it is not working, I used the same synax in my update event.

Author

Commented:
I found a solution. All i need to do was reference the cells as well as the row. The was no need to reference the control.

see below

protected void edit_record_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
delete_record_method.Record_ID = Convert.ToInt16(user_records.Rows[e.RowIndex].Cells[2].Text.ToString());
        delete_record_method.delete_record();
        BindData();
}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial