Welcome to MSDN Blogs Sign in | Join | Help

How to add Dynamic Data to an Existing Web Site

I've had various people ask me if Dynamic Data can be added to an existing website and I've compiled a list of steps to do this. We hope to add a tooling gesture to Visual Studio in the future to automatically do these steps. Once these steps are complete you can start taking advantage of Dynamic Data functionality in your existing applications.

1) Create a dummy Dynamic Data Website project. Copy the DynamicData directory from it into your existing website. You should also copy the Site.css and Site.master files. The Default.aspx file is optional, it display a menu of tables in your data model, this file is only needed if you plan on having such a menu in your application.

2) You can copy the Global.asax file or if you already have such a file you can just add the model registration and url routes as below to the

<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.DynamicData" %>

void Application_Start(object sender, EventArgs e) {

MetaModel model = new MetaModel();

model.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });

routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
    Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
    Model = model
});

}

 

3) In the <compilation> section in web.config add the following assemblies:

<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

 

4) In the <pages>/<controls> section add the following new tag prefix:

<add tagPrefix="asp" namespace="System.Web.DynamicData" assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

 

5) Enable the new ASP.NET Routing feature:

IIS 5/6/Casini

In the <httpModules> section add the following new module:

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

IIS 7

In the <system.webServer>/<modules> section add the following:

<remove name="UrlRoutingModule" />

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

In the <system.webServer>/<handlers> section add the following:

<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

At this point you need to register your Linq to SQL data modelin step #2 and optionally enable scaffolding by setting ScaffoldAllTables := true in the registratoin line. At this point if you copied the Default.aspx from the dummy Dynamic Data application you can execute it to view the scaffold. You can also enable Dynamic Data in existing web pages that use GridView, ListView, FormView and DetailsView by adding a DynamicDataManager to those pages and then registering the data control with the dynamic data manger:

 

<asp:DynamicDataManager id="DynamicDataManager1" runat="server">

<asp:GridView id="GridView1" runat="server">

...

DynamicDataManager1.Register(GridView1);

 

Inside of your GridView or DetailsView you can either use AutoGenerateColumns or you can use DynamicField controls in your column collections. If you are using ListView or FormView use DynamicControl to display values for each of your columns.

Published Monday, June 23, 2008 1:07 AM by scothu

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Pregnant Man &raquo; How to add Dynamic Data to an Existing Web Site

# How to add Dynamic Data to an Existing Web Application

Yesterday I posted about how to add Dynamic Data to an existing website and I got some feedback about

Tuesday, June 24, 2008 4:18 AM by Scott Hunter

# Adding Dynamic Data to Existing ASP.NET Sites

I posted back in May about the ability to combine standard ASP.NET webforms pages and ASP.NET Dynamic

Friday, June 27, 2008 10:51 AM by Mike Ormond's Blog

# re: How to add Dynamic Data to an Existing Web Site

I followed the steps outlined above with a couple of variations.

1.  I had to add the necessary references to the project, and change the copied objects namespace from the dummy dynamic data site to the current namespace.

2.  I was using the ADO.Net Entity Framework instead of the Linq to SQL data model context.  After I did the extra steps, the dynamic data seemed to work.  Now to modify and extend the scaffolding...

Hope this information helps!

Tuesday, July 08, 2008 11:03 PM by Jeff Chesney

# re: How to add Dynamic Data to an Existing Web Site

Good work Scott!

However, I'm having problem to display data in a GridView using DynamicFields when the data is retrieved from a stored procedure. It works as you described using for instance BoundFields but not using DynamicFields. The error I get is "The query results cannot be enumerated more than once."

I'm quite clueless on how to continue.

/Johan

Tuesday, September 16, 2008 10:05 AM by Johan Sundström

# re: How to add Dynamic Data to an Existing Web Site

This is very informative article and its very useful too.

Vikram Pendse.[Microsoft MVP]

Saturday, September 20, 2008 6:24 AM by Vikram Pendse

# re: How to add Dynamic Data to an Existing Web Site

������ ������� � WAP!

http://go4wap.net

Wednesday, October 01, 2008 5:19 AM by go4wap.net

# re: How to add Dynamic Data to an Existing Web Site

Shouldn't you also add <remove name="UrlRoutingHandler" /> under <system.webServer>/<handlers> section?

Thursday, January 29, 2009 4:40 PM by Girish

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker