Databases Reference
In-Depth Information
FIGURE 1.7 GridView with customer records from the Northwind Database.
ASP.NET also provides a data source control designed to work with Entity Framework. Data
source controls encapsulate the database operations needed by typical CRUD screens and
allow you to implement them declaratively, using markup instead of code. By changing
the previous example to use the EntityDataSource , you eliminate the code-behind file
while keeping functionality of the page intact.
LISTING 1.3 EntityDataSource Sample (Markup)
<%@ Page Language=”C#” MasterPageFile=”~/Site.master” %>
<asp:Content ContentPlaceHolderID=”main” runat=”server”>
<asp:GridView ID=”gridView” DataSourceID=”dataSource” runat=”server” />
<asp:EntityDataSource ID=”dataSource” runat=”server”
ConnectionString=”name=NorthwindEntities”
DefaultContainerName=”NorthwindEntities” EntitySetName=”Customers” />
</asp:Content>
The page in Listing 1.3 has an EntityDataSource control configured to access the
Customers table from the NorthwindEntities data model. The GridView control is now
data-bound declaratively, using the DataSourceID attribute, which contains the ID of the
EntityDataSource control.
 
Search WWH ::




Custom Search