Delete not working with LinqDataSource

by Cliff 30. June 2009

Recently I was working on a custom page in a Dynamic Data project and the "Delete" link was not working on a GridView that had a LinqDataSource as its data source.  Below are the steps I followed to resolve:

First, I was getting an error when clicking delete for a record in the GridView

LinqDataSource 'GridDataSource' does not support the Delete operation unless EnableDelete is true.' when calling method

This was fixed easily by setting EnableDelete="true" on the LinqDataSource.

Next up, I needed to set the DataKeyNames on the GridView.  This basically indicates what the where condition will be for the delete operation.  I set the GridView DataKeyNames equal to the name of the primary key column in my table.

That will probabaly resolve for most people, but for me, it did not.  I had also set the Select property on the LinqDataSource and this was preventing the delete from occuring.  Once I REMOVED the value for this propery, all worked.

The below article was helpful in diagnosing:

http://msdn.microsoft.com/en-us/library/bb514963.aspx

 

Cliff Gray's Info

Cliff Gray
Developer/Founder GrayTechnology.com.

E-mail me Send mail

Authors

Calendar

<<  June 2017  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

Blogroll

Download BlogEngine.NET

Download at CodePlex

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Subscribe