ASP.NET And LINQ


We can use Language-Integrated Query (LINQ) in Web pages to retrieve and modify data. LINQ applies the principles of object-oriented programming to relational data. It provides a unified programming model for querying data from different types of data sources, and extends data capabilities directly into the C# and Visual Basic languages.


We can use LINQ through the LinqDataSource control, through the ObjectDataSource control, or by creating LINQ queries.


The LINQ data source control follows the same thought stream asSQL data source (SDS) and Object data source (ODS) but works with LINQ data contexts and entities rather than database or plain classes. Just like SDS and ODS you can hookup the LINQ data source control to any data bound controls such as GridView and DetailsView.


LDS exposes several events that you can handle to get control of select, insert, update and delete operations. Here is the list :




  • Inserting

  • Inserted

  • Updating

  • Updated

  • Deleting

  • Deleted

  • Selecting

  • Selected



Creating ASP.NET page using LINQ


Create a new page called Untitled Page.aspx.  Within the .aspx page add a GridView control like so:









<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

      <head runat="server">

      <title>Untitled Page</title>

     </head>

     <body>

     <form id="form1" runat="server">

      <div>

    <asp:GridView ID="GridView1" runat="server">

    </asp:GridView>

    </div>

    </form>

     </body>

</html>



 

                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2012 VisualBuilder. All rights reserved