ASP.NET DynamicData: An Introductory Demo

I had a bit more time on my travels, so I cooked up this brief introduction to Dynamic Data.  I tried a different approach this time by showing what Dynamic Data adds to our existing data story. 

More information on Dynamic Data:

To do this demo, install Visual Studio 2008 SP1 and the Dynamic Data update.

I started off with a new, blank Dynamic Data Web Site


But rather than going directly into Dynamic Data features, I thought I’d review were we are today with .NET Framework 3.5 briefly. 

Add New Item and select "Linq to Sql Classes" (notice this works nearly the same with Entity Framework


Then add a couple of tables from Northwind.  I am using Products, Categories and Suppliers. 



Now add a new Web Form, creatively called Default2.aspx

In design View, add a GridView control and set up its datasource via the smart tag.

Use the LinqDataSource and change the table to Products


under Advanced, but sure to enabled Update.


Run it…

Overall this looks good. 


But there are a couple of areas it could get better.  For example, those IDs, they are meaningless to my users… I need to go in write code the handle them. 


And Validation, right now i just get an exception if invalid data is entered.


Ok, we have set the stage… Let’s see what help Dynamic Data can give us. 

First we need to enable Dynamic Data.  Like all good features, it is off by default!

In Global.asax, un comment out the model.RegisterContext method and set it to the NorthwindDataContext class.

    new ContextConfiguration() { ScaffoldAllTables = true });

In Default2.aspx, add the DynamicDataManager


Finally, in Default2.aspx.cs, in Page_Load() let’s ask our DynamicDataManager to mange our GridView.



Now, just a couple of tweaks to our Gridview, delete the columns collection, enable AutoGenerateColumns and AutoGenerateEditButton.  

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" 
        DataKeyNames="ProductID" DataSourceID="LinqDataSource1" AutoGenerateEditButton="True">

Run it…

Notice that Category and Suppliers have real names rather than IDs and when you edit them, you get a drop down for options.  Dynamic Data knows more about your data model and can therefore provide much better defaults.  



Data validation is a lot cleaner as well, notice how Dynamic Data pulls data validation from the model and does the right thing on the client? 



From here you can take advantage of all the other great Dynamic Data features to customize the UI.  More on that later.

Download the full sample

Comments (11)

  1. D. Ebdrup says:

    DynamicData is one of those things that should be enabled by default. I mean, heck – it saves several mintes of having to do INNER JOIN functions via SQL manually.

    Thanks for the tip, Brad. 🙂

  2. ASP.NET DynamicData: An Introductory Demo 自分でページを作成してGridViewを追加したものに、Dynamic Dataをどうやったら関連付けできるか、というサンプルが説明されています。…

  3. Ryan C Smith says:

    How do you add Dynamic Data Features to a site after the project had been created in the traditional way.  In other words I want to add Dynamic Data to my existing site.

  4. Steve says:

    Why do I add data source to my view ?

    My views don’t know anything about data?  Or is this for hobbist websites?

  5. I am working with a company called pixilfish, that incorporates silverlighght high definition video into your website

  6. Scott Hunter says:

    How do you add Dynamic Data Features to a site after the project had been created in the traditional way.  In other words I want to add Dynamic Data to my existing site.

    We are working on a tooling story that will give the option to add Dynamic Data to an existing site. Basic setps would be the following:

    1) Create a new Dynamic Data project. From that project drag the DynamicData directory, Site.css and Site.master, Global.asax into your existing project.

    2) You need to add references to System.ComponentModel.DataAnnotations, System.Web.Routing, System.Web.DynamicData to your project.

    3) From the blank DynamicData project there are a few items you will want to add to your web.config. The sections pages/controls and anything related to routing.

    I’ll get a post up on my blog on how to do this tonight.

  7. scott Hunter says:


    I need to know a little more in detail what you are talking about to answer your question. If you are talking about Views in the term of say MVC then you would be more interested in Dynamic Data for MVC. If this is not what you are talking about leave some more detail and I’ll try and answer your question.

  8. cmroanirgo says:

    Brad, I’m sorry (but not sorry enough to not comment) but MS’ stance regarding the wording of this technology is damnably confusing and isn’t dynamic from any standpoint.

    I have previously left comments on a previous article of yours.

    Considering that my ‘flame’ essentially quashed any discussion on my point…I did notice that no one has refuted my claim that Dynamic Data would be best used to describe some technology that is actually dynamic.

    2.5c (inflation hurts)

  9. Daiming Cao says:


    I hope about with you

  10. Daiming Cao says:

    Email error