Introduction to Dynamic Data

Get started with ASP.NET Dynamic Data with some practical advice.

In this show you will learn how to:

  • Start a dynamic data website from scratch
  • Create and maintain model meta-data
  • Create custom field templates
  • Use arguments passed in from the meta-data to field templates
  • Use third-party controls

In interest of keeping the screencast down to a manageable size I give you the tools you need to get started, but the code download has even more to offer than what you see in the demonstration.

In the download you get the following custom field templates:

  • AuditField: Many tables feature audit fields like the following: CreatedOn (DateTime), CreatedBy (varchar50), ModifiedOn (DateTime), ModifiedBy (varchar50) and IsDeleted (bit). Since Dynamic Data will render controls for all fields in the table, this field template helps you easily handle the data that these fields require.

    Generated data supported by the AuditField includes DateTime, UserName and Guid. You also have the option to overwrite existing data, as would be appropriate for fields such as the ModifiedOn field.

    For more details on how I implemented the AuditField check out my earlier posts:

  • URL: While in edit mode, this field template will allow you to test a URL before saving it to the database. Also if you want to save some keystrokes you can add a ";" at the end of a domain name. Once you move off focus of the textbox the control will add the obligatory "http://" for you. While in read only mode, URLs are rendered as links.

  • RichDateTime: While in edit mode this field template will render DateTime values with a date chooser control. I used the NetAdvantage ASP.NET WebDateChooser control. (See below for ways to get a trial or free copy for your use)

  • Email: While in edit mode, this field template will sanitize email addresses copied in from Outlook and Gmail. For instance if copy an email address directly out of an Outlook message you get text like this:



    John Doe [John.Doe@company.com]

    ...and out of Gmail you would get text like this:



    "John Doe" <johndoe@company.com>,

    ... in both instances the email address is cleaned up to be just the email address, or simply "johndoe@company.com".

    Note: I didn't type out the email address you see in the screen shots because of evil spammers!

The Code

The download includes the Dynamic Data website and a backup of the database I used to run the application. To get this site working on your machine I suggest you go through the following steps:

  1. Restore the DynDataDemo.bak file to your machine in SQL Server
  2. Open the website and delete the App_Code -> DemoDataContext.cs file
  3. Create a new file LINQ to SQL file named DemoDataContext.cs under App_Code
  4. Open the DynDataDemo database in the Sever Explorer and drag the Contacts table on to the LINQ to SQL designer; Save and Close
  5. Double check line 12 in the Global.asax to make sure the type name you are passing to the RegisterContext method is correct

...after thinking about it I wish I would have included these steps in the screen cast ;)

The only other consideration is that to get the RichDateTime field template to work you will need a copy of NetAdvantage for ASP.NET. You can download a trial version of the suite if you don't have a copy. (See below for a chance to win a free license as well!)

Go to the show notes page to download the code

Win a Copy of NetAdvantage for ASP.NET

The first person to email me the correct answer to the trivia question featured in the audio podcast will win a copy of NetAdvantage for ASP.NET. Yep - you have to listen to win :)

Resources

1 Comment

Comments have been disabled for this content.