Telerik blogs

UPDATE: You can download the latest Dynamic Data bits from here.

ASP.NET Dynamic Data

I am thrilled to announce that there is a new drop available for the ASP.NET Dynamic Data. You don’t know what the heck that is? It is the upcoming technology from the ASP.NET team which is designed to help you build web sites faster. Go check the following links immediately:

Points of extensibility

One of the key features of ASP.NET Dynamic Data are the DynamicField and his buddy the FieldTemplateUserControl.  DynamicFields represent the field of your objects. The FieldTemplateUserControl displays and edits the corresponding DynamicField – integer, decimal, date time etc.

Why do I need to know all that? Here is the answer - ASP.NET Dynamic Data is highly extensible. You can create custom FieldTemplate user controls – replace the built-in TextBox in Integer_Edit.ascx (used to edit integer fields) with RadNumericTextBox, integrate RadDatePicker to make choosing a date easier, use RadSlider to extend the paging mechanism etc. I have created a sample dynamic data web site with custom field templates all of which use RadControls for ASP.NET Ajax.
How to use it:
  • Download and install the latest preview of ASP.NET Dynamic Data. Get it from http://code.msdn.microsoft.com/dynamicdata
  • Download the sample site and extract the zip file somewhere. If you need to use the field templates in your project copy all user controls from ~/App_Shared/DynamicDataFields in your dynamic data web site.
  • Apply the RenderHint attribute to your objects specifying the field name and editor (find an example below)
To see a screenshot of the final result click here.

The RenderHint attribute

Of course the sample site I have built is using the Northwind database so I will show you how to use the custom editors with the Order class. To apply the render hint attribute you first need to add a new partial class in your App_Code folder with the same name as the object you want to customize. In my case I have added a partial class named Order. Then use the RenderHint attribute to specify the field name and editor:
[RenderHint("OrderDate""DateTimeTelerik")] 
[RenderHint("Customer""ForeignKeyTelerik")] 
[RenderHint("ShipVia""IntegerTelerik")] 
[Range("ShipVia", 1, 3)] 
[RenderHint("ShipName""TextTelerik")] 
public partial class Order 
 
The RenderHint attribute is used to hint the Dynamic Data runtime which user control must be used to display and edit a specific DynamicField. Keep in mind that RenderHint works only for objects of the specified type. For example applying the RenderHint attribute for the Order will take effect only for editing and displaying the Orders table from the Northwind database. You can however easily edit the default field template controls so you don’t have to apply the RenderHint attribute for every field of every object.


The sample web site provides custom FieldTemplateUserControls for editing integers, decimals, date time, text and foreign key.  GridViewPager.ascx is also modified to use RadSlider.

In conclusion, I would like to thank David Ebbo from Microsoft for holding my hand during the integration of RadControls with ASP.NET Dynamic Data.


About the Author

Iana Tsolova

is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.

Comments

Comments are disabled in preview mode.