views:

1391

answers:

5

I'm using a GridView in C#.NET 3.5 and have just converted the underlying datasource from Adapter model to an object which gets its data from LINQ to SQL - i.e. a Business object that returns a List<> for the GetData() function etc.

All was well in Denmark and the Update, and conditional Select statements work as expected but I can't get the Delete function to work. Just trying to pass in the ID or the entire object but it's being passed in a "new" object with none of the properties set. I'm just wondering if it's the old OldValuesParameterFormatString="original_{0}" monster in the ObjectDataSource causing confusion again.

Anybody have any ideas?

A: 

Have you tried checking if your delete command is being fired at all, with SQL Profiler or some profiler tool?

Jon Limjap
A: 

Yes - the delete function is being called in the business layer but the object being passed in is an "empty" object - i.e. it's not null but the members of the object are nulls and zeros.

Guy
+1  A: 

I found the solution. I had to set the GridView's DataKeyNames property to the unique key that my data was returning (in this case a classically named ID field). I'm guessing that this property "unset" itself when the Grid refreshed.

Guy
A: 

I found the solution. I had to set the GridView's DataKeyNames property to the unique key that my data was returning (in this case a classically named ID field). I'm guessing that this property "unset" itself when the Grid refreshed.

A: 

Thankyou. I couldn't find that answer anywhere!

Ben,That kind of thing belongs as a comment, not an answer
Andrew Shepherd
At the time of writing this Ben only had a rep of 1 - not sure if the comments link is available if you've got a rep of 1...?
Guy