Getting Started with the ADO.NET Entity Framework Part 4
This article is the final article of a 4-part series on the ADO.NET Entity Framework. This article will describe how to use the Entity Data Model and the Entity Data Source Control to implement a program using the Entity Framework. Using a GridView control to display bound data. Refer to the solution we created earlier using the Entity Data Model Designer and follow the steps below:
1. Drag and drop an Entity Data Source control from the toolbox onto your Default.aspx web form.
2. Click on the Configure Data Source option to specify the data source as shown below.
3. Specify the Connection String and DefaultContainerName and then click on Next.
4. Specify the fields you would want to retrieve from the database table and when done click Finish.
5. Drag and drop a GridView control from the toolbox onto the Default.aspx web form as seen below.
6. Use the Choose Data Source option of the GridView control to associate its data source with the Entity Data Source control we created earlier. Refer to the following figure:
Below is how the markup code of the GridView control looks with its templates defined. Note how the DataSourceID of the GridView control has been associated with the Entity Data Source control created earlier.
<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=
DataSourceID=”SqlDataSource1″ BorderColor=”Black” BorderStyle=”Solid” Width=”400px”>
<asp:BoundField DataField=”EmployeeID” HeaderText=”Employee ID” ReadOnly=”True” SortExpression=”EmployeeID” />
<asp:BoundField DataField=”FirstName” HeaderText=
“First Name” SortExpression=”FirstName” />
<asp:BoundField DataField=”LastName” HeaderText=
“Last Name” SortExpression=”LastName” />
<asp:BoundField DataField=”Address” HeaderText=”Address” SortExpression=”Address” />
It’s now done! When the application is executed, the output should be similar to what is shown below:
This series of articles has discussed how to get started with the ADO.NET Entity Framework. Learning how to create an Entity Data Model and use it along with the Entity Data Source control to bind data to a GridView data control.