ASP.NET 4.0 and the Entity Framework 4 - Part 5 - Using the GridView and the EntityDataSource
page 4 of 7
by Vince Varallo
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 34837/ 103

Step 3: Create the Web Form

Now that you have and entity data model you can create a web form that will use this model.

1.    Right click on the web site in the Solution Explorer and select Add New Item… from the pop-up menu.

2.    Select Web Form from the list of templates and leave the name of the file set to Default.aspx.  click the Add button

3.    The Default.aspx web form will be added to your project and the markup is displayed.  Switch your view to Design mode.

4.    Expand the Data node in your toolbox and you should see the EntityDataSource control.  Drag this control onto your web form.  You can drop it anywhere on the form.

5.    Click the smart tag on the EntityDataSource control and select Configure Data Source from the pop-up menu.  The Configure Data Source wizard will appear.

6.    Choose AdventureWorksEntities from the list of Named Connections.  The DefaultContainerName will default to AdventureWorksEntities.  Click the Next button.

7.    Select Contacts for the EntitySetName and select Contacts for the EntityTypeFilter.

8.    Check the boxes to enable updates and deletes.

9.    Click the Finish button.

10. The entity data source is now configured so it can be bound to a GridView control.  Drag a GridView control onto the form.

11. Click the smart tag to display the pop-up menu next to the GridView if it doesn't appear by default.

12. Set the Choose Data Source list to EntityDataSource1.

13. Check the boxes next to Enable Paging, Enable Editing and Enable Deleting.

14. Click the Edit Columns… link from the pop-up menu.  You should see all of the fields listed in the Selected Fields list.

15. Click on the ContactID field and change its Visible property to False.  Do the same for the NameStyle, EmailPromotion, Phone, PasswordHash, PasswordSalt, AdditionalContactInfo, rowguid, and ModifiedDate fields.  Click the OK button.

16. Your web form should look like the following image.

17. Right click on the Default.aspx page and set it as the start up page.  Run your project by pressing F5.

18. You'll get a message asking if you want to modify the web.config file to enable debugging.  Click the OK button.

The web page should be displayed with the list of contacts in the table.  If you click on the Edit link each cell in that row will become a textbox and you'll be able to change the value.  To commit the changes to the database click the Update link.

View Entire Article

User Comments

Title: vb nvvbnvb   
Name: vbnvbn
Date: 2012-06-06 10:09:02 PM
Title: Cant see images   
Name: jrk
Date: 2012-05-25 9:27:32 PM
The images in this article show as big red X
Title: great done   
Name: vishwajeet singh
Date: 2010-09-30 6:44:04 AM
its realy great thing what happend through .net 4.0

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-18 4:16:50 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search