Introduction: in this post I will discuss how to create a GridView whose data source is a LinqDataSource. The application will support the following features:
- Paging, editing, deleting, and insertion of a new entry.
- Using some AJAX controls AjaxControlToolkit such as CalenderExtender.
- Validation using RegularExpressionValidator (inside the grid).
- Cleaning up the foreign-key values & replacing them with their values (Binding UI with ASP LinqDataSource).
Part 1 Abstract: you will expect in this part to know about:
- Paging, editing, deleting.
Resources: Visual Studio 2008, SQL Server 2005 Express Edition
Prerequisites: Readers of this post must have a good knowledge about ASP.Net and LINQ to SQL, I will suppose that you know how to create and use Data Classes our .dbml file should look like this :

In this tutorial our data source is Microsoft Northwind Sample database we will show the Orders table in the GridView.
Let’s get started.
I just dragged and dropped a GridView from the ToolBox.

Step 1: We need to Create a LinqDataSource, this can be done easily using the wizard as follows:

Step 2: Select LINQ then press next

Step 3: Make Sure that u selected the appropriate Data Classes

Step 4: Select thr required table (in our case Orders) and click Advanced

Step 5: Make sure that the Check Boxes are checked, this sets the properties of the LinqDataSource which are EnableDelete, EnableInsert, and EnableUpdate to true.

Step 6: Make sure that the Grid enables paging, sorting, editing, and deletion. I am not concerned about selection in this article.

Now let’s run the project and see what we get

If I click delete, the order will be deleted from the database
, if I click update the following will happen:

Marvelous and simple!!
Update some values then click update it will reflect in the database.
What I have done is the simple part; I almost used Wizards and UI.
I haven’t yet completed writing this article but this is the end of this part.
Mohamed Atia
MCTS