Click here to Skip to main content
13,350,985 members (55,406 online)
Click here to Skip to main content
Add your own
alternative version


52 bookmarked
Posted 2 Oct 2008

Introduction to ASP.NET Dynamic Data Part - I

, 2 Oct 2008
Rate this:
Please Sign up or sign in to vote.
An article on ASP.NET Dynamic Data


ASP.NET Dynamic data allows us to create data driven websites in minutes. ASP.NET Dynamic data comes as a template with VS2008 SP1. Using this template we can create a fully running website without writing a single line of code.

This part of the article will walk you through the features such as Insert/Update/Delete for all tables. Validations on the fields while editing. Paging and sorting for the data displayed from tables.


When developing any data driven website we could not forget to maintain code tables, we create an interface to maintain code table information. For each project I have been doing this and repeating the code for each table. After awhile we developed a common code to maintain a code table for all applications. But when I saw ASP.NET Dynamic data I was knocked of my feet. It does create every single line of code for us to maintain database tables. We can do all functions on the tables that are needed in the real world like, Insert/Update/Delete. On top of that it allows us to modify the code depending on our needs. ASP.NET Dynamic data uses the LINQ to SQL class to store metadata of our database tables and uses that metadata to build a fully dynamic site. Initially, ASP.NET Dynamic data supported only SQL server as a database but with the new release, the LINQ to Entities class is supported which can be used for any database.

Using the Code

To get ASP.NET Dynamic data working on your m/c you will have to install VS2008 SP1.

Once you install SP1, start Visual Studio and create a new website.

Let's pick "Dynamic Data Web Site" from the list.

Dynamic Data Web Site

In this example we are going to use SQL Server as a database, so let's add Northwind database to our App_Data directory.

Now, let's create a LINQ to SQL class for our website.

LINQ to SQL Class

After creating a LINQ to SQL class, drop a couple of tables on the class. When we drag these tables on the LINQ to SQL class, it internally creates one class for each table. And the columns of the table are created as properties to the class. This class also stores the type of the column and that information is used to provide validation for the fields while editing.

LINQ to SQL Class with metadata Info

Now let's go and enable the website for ASP.NET Dynamic data. To do this we need to go to the global.asax file. You will find some lines of commented code, we need to uncomment the line where we register datacontext. We also need to set ScaffoldAllTables = true, this will enable all tables dragged on LINQ to SQL class for Insert/Update/Delete functionality.

We can do it as shown below:

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

That's all we have to do, let's hit F5 to run the website.

We get list of tables on the screen and when we go the tables by clicking the link we get a list of records. We can do Insert/Update/Delete on our tables.

Dynamic Data Page with Inser/Update/Delete Functionality

Let's see the validation provided by ASP.NET Dynamic Data. Click edit link on any record in the order_details table — the "quantity" column is declared as Integer in the database. When we try to put a non-integer value in that field we get an error saying that the column is Integer. Similarly, if the column is declared as not null in a database a required field validator is applied on field.

As I mentioned earlier the LINQ to SQL class stores metadata and applies validations on the fields.

Integer Validation Null Validation

ASP.NET Dynamic Data also provides sorting and paging by default, as seen in image below:

Dynamic Data Page with Pagination

ASP.NET Dynamic Data also recognizes foreign key relations between the tables. Foreign keys are displayed as links and when we click on the link we are taken to the parent table. This is one of the amazing features of ASP.NET Dynamic Data.

Let's consider one example:

ProductID is a foreign key in the Categories table, when we see a list of records in the categories table the data in Product column is shown as a link. On clicking of "View Products" we go to the page showing a list of products.

Dynamic Data Page with Pagination

As shown in the image below, we can see the list of products. If you see carefully we get the list of products filtered by category. The dropdowns provided at the top are filters for the relations between the tables.

Product details filtered on category

We have achieved all these functionalities for our tables without writing a line of code and that’s what we need for code tables in our applications.

ASP.NET Dynamic Data can be used for code table maintainance, but that is not the only use of it. We can use dynamic data for prototyping the applications, rapid development of web sites, and, most importantly, we can customize a whole web site depending on our needs.

When we create a new web site using a Dynamic Data template we get a Directory named "DynamicData", this directory holds all the code to do the magic that we saw in this article. We have whole code so we can modify it to fulfill our needs.

Dynamic Data is based on generic design. There are predefined templates for each functionality. Displaying Data from each table is done using List.aspx, displaying details of record is done ListDetails.aspx page, displaying Edit template is done using Edit.aspx page and so on...

Because of this generic structure we have the ability to customize a whole web site and I am going to discuss how to customize Dynamic Data templates in next part of this article.

Points of Interest

In this article we saw the simplicity of design allowing us to create a whole web site in a couple of minutes, but the real fun lies in customizing what is available and we can take it to any level depending on our imagination.


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


About the Author

Software Developer (Senior)
United States United States
Amit is working at Palm Beach County Florida as sr. Programmer. He has been working on .Net technologies since 4.5 years. He is mainly involved in web technologies.

You may also be interested in...


Comments and Discussions

Questionhow can i modify dropdownlist values? Pin
sumitp1714-Sep-12 3:17
membersumitp1714-Sep-12 3:17 
QuestionGood One Pin
Davda25-Apr-12 1:45
memberDavda25-Apr-12 1:45 
GeneralMy vote of 1 Pin
bluesoniq25-Aug-10 3:50
memberbluesoniq25-Aug-10 3:50 
GeneralMy vote of 1 Pin
poortl910930-Sep-09 13:50
memberpoortl910930-Sep-09 13:50 
GeneralMy vote of 1 Pin
Mitri10-May-09 10:39
memberMitri10-May-09 10:39 
GeneralMy vote of 1 Pin
Caio Kinzel Filho16-Jan-09 0:49
memberCaio Kinzel Filho16-Jan-09 0:49 
GeneralNice article Pin
Vishal Shukla14-Oct-08 3:23
memberVishal Shukla14-Oct-08 3:23 
GeneralRe: Nice article Pin
Andrew J Dixon12-Nov-08 12:49
memberAndrew J Dixon12-Nov-08 12:49 
GeneralIts nice to see in text form, but this is exactly the video from Pin
Jay R. Wren6-Oct-08 15:02
memberJay R. Wren6-Oct-08 15:02 
GeneralRe: Its nice to see in text form, but this is exactly the video from Pin
amit@sunshine11-Oct-08 6:09
memberamit@sunshine11-Oct-08 6:09 
GeneralGood start ... looking forward to more ... Pin
BillWoodruff2-Oct-08 21:32
memberBillWoodruff2-Oct-08 21:32 
GeneralRe: Good start ... looking forward to more ... Pin
amit@sunshine11-Oct-08 6:10
memberamit@sunshine11-Oct-08 6:10 
GeneralThank you! Pin
Koltz2-Oct-08 20:43
memberKoltz2-Oct-08 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 2 Oct 2008
Article Copyright 2008 by amit@sunshine
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid