Home » Windows OSRSS

Simple LINQ & GridView Question - how to edit data?

Hi,

I am just beginning to work w/ LINQ. I have a data model set up and put a LinqDataSource and GridView on a page. It binds & displays ok, including paging and sorting.

How do I enable editing? I followed a blog by ScottGu to edit using the GridView. Clicking on the smart tag of the GridView in Design view, there are no checkboxes to enable editing or deletion, as there would be for a SqlDataSource bound grid. I thought the LinqDataSource enabled two way binding, similarly to the SqlDataSource. Is this not correct?

If it is correct, how to do I enable editing? I have configured the LinqDataSource to enable automatic deletes, inserts and updates. I have also tried manually adding a CommandField column to the GridView. Nothing seems to work. Here is the markup for the LinqDataSource:

<asp:LinqDataSource ID="LinqDataSource1" runat="server"
    ContextTypeName="AdventureWorksDataContext"
    EnableDelete="True" EnableInsert="True" EnableUpdate="True"
    Select="new (ProductID, Name, MakeFlag, SafetyStockLevel, ReorderPoint)"
    TableName="Products">
</asp:LinqDataSource>

Thanks.

Dan

 

4 Answers Found

 

Answer 1

Check Scottgu's blog  he has a full tutorial on how to integrate linq  and asp.net using linqdatasource  and GridView

LINQ to SQL (Part 9 - Using a Custom LINQ Expression with the <asp:LinqDatasource> control)
Pedro Rainho
 

Answer 2

LinqDataSource uses the same interfaces as other data  source controls; the values are still passed back to the datasource using 2-way databinding from the databound control.  To enable  editing, you must make sure that the ContextTypeName and TableName refer to a valid LINQ to SQL data context and table, you must set  EnableUpdate=true on the data source.  You must also ensure that the databound control is configured  for editing, which includes setting the DataKeyNames property where it exists.

 
 

Answer 4

thanks, I was also looking something like this. 
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter