Click here to Skip to main content
6,595,444 members and growing! (15,424 online)
Email Password   helpLost your password?
Web Development » ASP.NET » Data     Beginner License: The Code Project Open License (CPOL)

First Step into the ASP.NET Dynamic Data

By Khandakar Fazley Rabbi

Life make easy to create data driven websites.
Windows, .NET (.NET 3.5), ASP.NET
Posted:21 Nov 2008
Views:7,935
Bookmarked:15 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 1.26 Rating: 1.80 out of 5
3 votes, 60.0%
1

2

3

4
2 votes, 40.0%
5

1.JPG

Introduction

ASP.NET Dynamic Data provides a framework that enables you to quickly build a functional data-driven application, based on a LINQ to SQL or Entity Framework data model. It also adds great flexibility and functionality to the DetailsView, FormView, GridView, and ListView controls in the form of smart validation and the ability to easily change the display of these controls using templates. Dynamic Data is part of the .NET Framework version 3.5 SP1 release.

Background

We want to create a web site and we will see couple of temple after installing SP1, One is “Dynamic Data Website” and other is “Dynamic Data Entity Website”. Here we are now going to create our first Dynamic data web site by generating some Scaffolding. Below we can see the files automatic generated by the template.

2.JPG

Using the Code

The code that has been generated is massively flexible. So you can basically update every single detail how your application works and how your data will appear. It is not the other type of code generation. And, this is not all about code generation; code generation is only a feature of Dynamic data. So you can choose code generation or not to generate any code that you can start from the scratch or you can add dynamic data to your existing application First of all you can see a Global.asax file added to your application. Dynamic data application is depends on some settings that is managed from Global.asax file. The other thing is “Dynamic Data” directory. Under the directory you can look up at the section “Page Templates”. Note that, there have all the pages that might be use in a database application. You need to remember that those are only templates and you do not have selected any database so far! So this is not database specific, this is highly template model. You can also create new templates or table specific pages to work with your application. Next, you can see “field templates”. There you can see lot of ascx control files. Notice, you can see Text, Integer, Boolean, DateTime and for many of this you have Text.ascx, Text_Edit.ascx for Text. In this case, for the TextFields Text.ascx for viewing a Text field in a non-editable fashion and Text_Edit is for the edit experience for the particular field. And again these are templates so, you can modify a one of the text templates to change how a text box get displayed anywhere in your application. Now you can see a custom page section. You can add custom pages whatever you want to create and call from your application.

3.JPG

The next thing is we need to add some data to our application. I used Northwind sample database for this application. I created connection through Server Explorer.

4.JPG

Now we need to add some API to access our database. So to get that, I used “Linq to SQL Classes”

5.JPG

Here you can see in the “NorthwindDataContext” is our Data Context. And this is the main entry point to our database operation.

6.JPG

Now I’ve selectively chosen some tables and drop it to the dbml designer. Note that the background CS code should be updated. You can see the table and the relations on the designer.

Now let’s see our Global.asax file. It is very important to get acknowledged about the file.

8.JPG

Here "YourDataContextType" is our "NorthwindDataContext" And also at the end of the code you can see { ScaffoldAllTables = false }. It is false by default because you might not want scaffolding to the entire schema. Here in my article I’ve make the scaffolding to true as I don’t like to make any custom pages and so that dynamic data runtime can generate all the scaffolding for us. With that we have the project and run the project.

 
        model.RegisterContext(typeof(NorthwindDataContext), new ContextConfiguration() { ScaffoldAllTables = true });

        // The following statement supports separate-page mode, where the List, Detail, Insert, and 
        // Update tasks are performed by using separate pages. To enable this mode, uncomment the following 
        // route definition, and comment out the route definitions in the combined-page mode section that follows.
        routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
            Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
            Model = model
        });

10.JPG

That's all. You can see styles have been added to the scaffolding code as because a css file is added to the entire application. You can modify the CSS or add custom inline styles to the template.

Points of Interest

I’m interested on the latest .NET technologies and the best practices.

History

21th November 2008. 1st Draft.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Khandakar Fazley Rabbi


Member
I work for SoftwarePeople. See my linkedin profile here
Occupation: Team Leader
Company: SoftwarePeople| Enfatico
Location: Bangladesh Bangladesh

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralMy vote of 1 PinmemberBrady Kelly6:11 24 Oct '09  
GeneralNce article Pinmembersathya_svce0:56 11 Oct '09  
GeneralMy vote of 1 PinmemberMarek Konieczny5:29 25 Nov '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Nov 2008
Editor: Sean Ewington
Copyright 2008 by Khandakar Fazley Rabbi
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project