tags:

views:

112

answers:

2

hi

1) Why can we update data records ( via data source control ) without setting GridView.DataKeyNames property, but when deleting ( and if ConflictDetection property is set to the OverwriteChanges ), DataKeyNames must be set, else GridView will not pass parameters to data source control?

Thank you

+1  A: 

I think that the documentation explains it best. It states that the DataKeyNames property is "an array that contains the names of the primary key fields".

When you modify the gridview dynamically builds up the values from the row and passes them into the datasource. When you delete, it assumes all that is needed are the primary keys. Conveniently these are stored in the DataKeys for that row, so they are the only values you get.

Brendan Kowitz
+2  A: 

GridView uses DataKeyNames as identifiers to the records that you want to manipulate. Just like primary keys on your tables. They're roughly used on WHERE clause of your operation.

Canavar