In this post I will walkthrough on using ASP.Net Gridview with LinqDatasource.
You can bind a GridView with LinqDataSource and would able to
- Edit
- Delete
- View data without writing a single line of code.
To see how it works , follow the steps below;
Step1
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
Follow @debugmode_
***********************
thanks 🙂
nice,simple one
Thanks
thanks. really simple and working solution
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….
http://msdn.microsoft.com/en-us/library/bb907622.aspx
http://mindstick.com/Articles/9ca8fabd-49ef-4e4d-855b-74fc523d9138/?LINQ%20%28Language%20Integrated%20Query%29
http://www.codeproject.com/Articles/188935/LINQ-Demo-with-ASP-NET-Web-Application
Lastly, I would like to say thanks to everyone for your precious post.
Not working for edit and delete LinqDataSource ‘LinqDataSource1’ does not support the Select property when the Delete, Insert or Update operations are enabled.
PLEASE HELP ME ?
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