Academic Students Projects | Software School Projects | Free Source Codes | College
Projects By LANGUAGE
Libraries
Articles & seminars
Source Code

The price of the projects include source code, abstract, report and support for development and deployment. Please use our contact us form or send email to Support@srishtis.com

 

 

Performing CRUD and Grouping Operations with the LinqDataSource Control Build fully-editable Create, Read, Update, and Delete (CRUD) database front-ends easily and discover how to group and aggregate data using the new LinqDataSource control in ASP.NET.
This tutorial builds on that foundation by discussing more sophisticated features for creating fully-editable pages, such as adding Create, Read, Update, and Delete (CRUD) capabilities, and handling CRUD events generated by the LinqDataSource control. In addition, this installment also demonstrates how to aggregate and group data using the LinqDataSource control.
CRUD with LinqDataSource
To begin, create a new Visual C# web site named LinqDataSourceExample. After creating the web site, select Website → Add New Item from the menu. In the Add New Item dialog box, select the "LINQ to SQL Classes" template, and name it AdventureWorksDatabase.dbml. You'll see the Object Relational Designer view of the newly created class. From that view, select View → Server Explorer from the menu, and add a new data connection to the AdventureWorks database. Finally, to create the corresponding entity classes, drag and drop the Production.ProductCategory, Production.ProductSubcategory, and Production.Product tables onto the Object Relational Designer from the Tables node in Server Explorer.
The next step is to create an ASP.NET page that uses the LinqDataSource control to create CRUD capabilities on top of the Product table in the AdventureWorks database. Create a new ASP.NET page named CRUD_Example.aspx and modify its code as follows:
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Using LinqDataSource Control for Create, Read, Update and Delete Operations</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView DataSourceID="productSource"
DataKeyNames="ProductID" AutoGenerateEditButton="true"
DataKeyNames="ProductID" AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true" AllowPaging="true"
AutoGenerateInsertButton="true" ID="productsView"
runat="server">
</asp:DetailsView>
<asp:LinqDataSource ID="productSource" runat="server"
ContextTypeName="AdventureWorksDatabaseDataContext"
TableName="Products" EnableUpdate="true" EnableInsert="true"
EnableDelete="true">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
The LinqDataSource control in the preceding code has three properties: EnableInsert, EnableUpdate, and EnableDelete. All three are set to true to enable automatic insert, update, and delete support. You need to enable the same functionality at the data-bound control, DetailsView in this case. To accomplish this, you set the AutoGenerateInsertButton, AutoGenerateEditButton, and AutoGenerateDeleteButton of the DetailsView control to true. That's all you need to do to enable CRUD operations with the LinqDataSource control.
Download Code