In this post I will walkthrough on using ASP.Net Gridview with LinqDatasource.
You can bind a GridView with LinqDataSource and would able to
- View data without writing a single line of code.
To see how it works , follow the steps below;
Crate a ASP.Net Web Application.
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.
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
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
Leave a Reply