Introduction
As we all know about GridView, it is a Data Control of ASP.NET which is used to display sata in tabular format.
Lambda Expression
Lambda expression facilitates functional programming. It’s an Anonymous Function.
Syntax:
(Input=>Expression )
Features:
- Using Anonyms variable/parameters.
- No need to define scope like curly braces.
- No need to return.
LINQ Query (Language Integrated Query):
In simple terms, LINQ provide us the facility to interact from front end to databases without directly using and ADO.NET Classes.
In other words, LINQ is a collection of Extension Methods.
Syntax:
From<range variable> IN <IEnumerableCollection >
The following are the basic methods of LINQ:
More about LINQ.
Demonstration
Step 1: Open Visual Studio, click Add, then new Web Site:
Add LINQ to SQL Classes:
Step 2: Drag your SQL Table to dbml Layout:
It will automatically create Class , Collection and Properties.
- Class: DataContext, Departmeant
- Collection: Departments
- Proreties: DeparmentID,DeapartmentName ,CapLimits, Location
Step 3: Add a GridView Control to the form and bind accordingly:
Step 4: In Code Behind (.cs Page):
- To Bind Grid View:
- For Insert and Delete:
- For Update:
Output will look like the following:
Hopefully, this article will help you to work on GridView and LINQ.