Introduction to Dynamic Data
Get started with ASP.NET Dynamic Data with some practical advice.
Listen to the Show
Watch the Screen Cast
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 obiligatory "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" <firstname.lastname@example.org>,
... in both instances the email address is cleaned up to be just the email address, or simply "email@example.com".
Note: I didn't type out the email address you see in the screen shots because of evil spammers!
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:
- Restore the DynDataDemo.bak file to your machine in SQL Server
- Open the website and delete the App_Code -> DemoDataContext.cs file
- Create a new file LINQ to SQL file named DemoDataContext.cs under App_Code
- Open the DynDataDemo database in the Sever Explorer and drag the Contacts table on to the LINQ to SQL designer; Save and Close
- 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!)
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. You have to listen to win :)
- Official Dynamic Data website
- New ASP.NET Dynamic Data Support - Scot Guthrie's original post
- VS2008 and .NET 3.5 SP1 has some nice changes for Dynamic Data
- Infragistics NetAdvantage and Dynamic Data - Infragistics is getting busy on DD