LINQ - ASP. Net
LINQ - ASP.Net
As a set of .NET Framework extensions, LINQ is the preferred mechanism for accessing data from ASP.NET developers. ASP.NET 3.5 has a built-in LINQDataSource control tool that makes it easy to use LINQ in ASP.NET. ASP.NET uses the control mentioned above as a data source. The actual projects mostly encompass websites or Windows applications. To better understand the concept of LINQ with ASP.NET, let's start by creating an ASP.NET website that uses LINQ functionality.
For this it is essential to install Visual Studio and .NET Framework on your system. Once you've opened Visual Studio, go to File → New → Website. A pop-up window will open as shown in the figure below.
Now under the models on the left side there will be two options of language to create the website. Choose Visual C # and select ASP.NET Empty Website .
Select the folder in which youwant to save the new website to your system. Then press OK and soon Solution Explorer will appear on your screen containing all the web files. Right-click Default.aspx in Solution Explorer and choose View in Browser to display the default ASP.NET website in the browser. Soon your new ASP.NET website will open in the web browser as shown in the following screenshot.
.aspx is actually the main file extension used in ASP.NET websites. Visual Studio by default creates all the pages needed for a basic website like the homepage and the About Us page where you can conveniently place your content. The website code is automatically generated here and can also be viewed.
It is possible to UPDATE, INSERT a DELETE data in the pages of the ASP website. NET using the LINQDataSource control.There is absolutely no need to specify SQL commands because the LINQDataSource control uses dynamically created commands for such operations.
The control allows a user to use LINQ in an ASP.NET web page in a convenient way by setting the property in the markup text. LINQDataSource is very similar to controls such as SqlDataSource as well as ObjectDataSource because it can be used to bind other ASP.NET controls present on a page to a source of data. So, we need to have a database to explain the various functions invoked by the LINQDataSource control.
Before you start explaining how to use the control in the ASP.NET web page form, it is essential to open the Microsoft Visual Studio toolbox and drag and drop the LINQDataSource control on the .aspx page of the ASP.NET website as shown below.
The next step is to configure LINQDataSource by selecting all the columns in the employee registration.
Now add a GridView control to the .aspx page et configure it as shown in the figure below. The GridView control is powerful and provides flexibility for working with data. Shortly after configuring the field, it will appear in the browser.
The encoding that can be viewed now on your screen for the .aspx page will be -
Here it is appropriate Note that it is vital to set the ContextTypeName property to that of the class representing the database. For example, here it is given as LINQWebApp1.AdventureWorksDataContext because this action will establish the necessary connection between LINQDataSource and the database.
INSERT, UPDATE and DELETE data in ASP.NET Page using LINQ
After rigorously following all of the above steps, choose LINQDataSource tasks in the LINQDataSource control and check the three boxes to enable insert, enable update, and enable deletion in ditto, as shown in the following screenshot.
Declarative markup will be displayed soon on your screen like the following.
Now that there are several Rows and Columns, it is better to add another control on your .aspx form named as Detail View control or Primary Control under Grid View control to only show details of a selected grid row item. Choose the detailed view tasks in the Detailed View control and check the boxes as shown below.
Now just save the changes and press Ctrl + F5 to display the page in your browser where it is now possible to delete, update, insert any recordegistrement on the detailed view control. asp:>