Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

Specified argument was out of the range of valid values.

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.
0
Mr_Shaw
Asked:
Mr_Shaw
  • 2
1 Solution
 
rionrocCommented:
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.
:)
0
 
Mr_ShawAuthor 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.
0
 
Mr_ShawAuthor 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();
}
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now