>The error is pointing to this line:
>myCommand.Parameters("@id").Value = Me.grdProducts.DataKeys(CInt(e.Item.ItemIndex))
>
>Error message is:
>"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
>
>I have done the following trying to solve this problem but nothing yet:
>I have added a primary key to my table.
>I have added a column to my grid to display the primary key field.
>
>Any suggestions?
Chris,
I'm sorry for not replying sooner.
Instead of using the DataKeys collection, use the primary key column's control:
myCommand.Parameters("@id").Value = CType(e.Item.FindControl("myPKLabel"), Label).Text