ASP.Net GridView with LinqDataSource

In this post I will walkthrough on using ASP.Net Gridview with LinqDatasource.

You can bind a GridView with LinqDataSource and would able to

  1. Edit
  2. Delete
  3. View data without writing a single line of code.

To see how it works , follow the steps below;


Crate a ASP.Net Web Application.


Step 2

Right click and add a new item in ASP.Net Web Application project. Choose LINQ to SQL class from Data tab.


Drag and drop tables from Server Explorer to generate Data Context class. I am creating Data Context class from School Database by selceting Person table.


Now Data Context class has been created.

Step 3

Go ahead and drag and drom a GridView on Default.aspx page.


Switch to the design view on Default.aspx page . Select Properties of GridView by clicking on the arrow key at right top of GridView and then Choose Data Source option selcet New data source.


From the dialog box you need to choose LINQ and if you want you can edit the data source name as well. I am leaving default data source name LinqDataSource1


Next you need to choose the context object . We have already created DataContext named DataClasses1DataContext1 .Choose DataClasses1DataContext1 as context object .


After choosing context object click on Next button . From next dialog box choose table and columns you want to bind grid view . Click on the advanced button,


Since you want data in grid view editable. So go ahead and checked all the three options.


Click Ok and clcik on Finish

Step 4

Since you want to Edit, Delete and Insert data from Grid View. So open properties of GridView and enable the options by cheking the chekboxes.



You have done it . Press F5 to run the appliction. You would able to Edit, Delete and View the data in Grid View without writing a single line of code.


I hope this post was useful. Thanks for reading Smile




Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

7 responses to “ASP.Net GridView with LinqDataSource”

  1. nice,simple one

  2. thanks. really simple and working solution

  3. Thank you very much. This has become my best material on LINQ topic. You made it very simple and understandable, thanks for sharing with us. Some other good articles on LINQ I was found over internet during searching this topic which also explained very well about LINQ, URL links of those posts are….

    Lastly, I would like to say thanks to everyone for your precious post.

  4. Not working for edit and delete LinqDataSource ‘LinqDataSource1’ does not support the Select property when the Delete, Insert or Update operations are enabled.


  5. Can you give me one example on the same thing
    display two tables data in a single Gridview And also perform Update delete operations,
    any methos plz help me the complete simple example

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at