One of the things that we worked on supporting in Dynamic Data is the ability for third party controls like Grids to be able to host DynamicControls. Basically allowing the developer to use controls that are fancier or have more features then the stock controls in ASP.NET with Dynamic Data.

For the first version of Dynamic Data we tried we ran into various limitations because it was delivered in a service pack which limited what type of changes we could make in the framework. Basically we were able to add new API’s but had little ability to change existing API’s.

One of the limitations this placed on controls was that to support Dynamic Data they would need to derive from DataBoundControl because there were no interfaces that controls could implement to indicate that supported basic data binding operations. Some control vendors want to be able to derive their controls from Control to make them as lightweight as possible and to have the best performance.

To solve this in .NET 4.0 we are adding new interfaces that controls can implement that indicate that they do databinding and also indicate whether the control displays a single item or a list of items. Here is a breakdown of the new interfaces:

 

public interface IDataBoundControl

Interface for accessing the common properties for data bound controls.

string DataSourceID { get; set; }

Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.

IDataSource DataSourceObject { get; }

Gets the actual data source control when DataSourceId is set.

object DataSource { get; set; }

Gets or sets the object from which the data-bound control retrieves its list of data items.

string[] DataKeyNames {get; set; }

Gets or sets an array that contains the names of the primary key fields for the items displayed in a control.

DataBoundControlMode Mode { get; }

Gets whether the control is in ReadOnly, Edit or Insert mode.

string DataMember { get; set; }

Gets or sets the name of the list of data that the data-bound control binds to, in cases where the data source contains more than one distinct list of data items.

 

public interface IDataBoundListControl

Interface for data bound controls that display multiple rows and can selection.

DataKeyArray DataKeys { get; }

Gets a collection of DataKey objects that represent the data key value of each row in a GridView control.

DataKey SelectedDataKey { get; }

Gets the DataKey object that contains the data key value for the selected row in a GridView control.

int SelectedIndex { get; set; }

Gets or sets the index of the selected row in a GridView control.

string[] RowClientIDSuffix { get; set; }

 

bool EnablePersistedSelection { get; set; }

Gets or sets whether the selection is based on index or on data keys.

 

IDataBoundItemControl

Interface for data bound controls that display a single item.

DataKey DataKey { get; }

Gets a DataKey object that represent the data key value of the row in a control.

 

IFieldControl

Interface for data bound controls that can automatically generate their fields based on data.

IAutoFieldGenerator FieldsGenerator { get; set; }

Gets and sets the IAutoFieldGenerator which generates the fields.

 

IDataBoundControl is implemented by a control to indicate that it support data binding. This includes datasources, primary keys and the mode the control operates in. IDataBoundListControl indicates a control that displays data in a list and supports selection. IDataBoundItemControl indicates a control that displays a single record at a time. And IFieldControl is for controls like GridView or DetailView that have the ability to autogenerate their columns. These new interfaces are implemented across all the standard data controls in 4.0 including ListView, GridView, DetailsView and FormView. If third party controls support these interfaces they will be usable with Dynamic Data.

One of the control vendors DevExpress has recently implemented Dynamic Data support without these interfaces in their grid control. Here is a very cool screencast by Mehul Harry that demonstrates their grid and Dynamic Data in action. With these new interfaces they will be able to support their spreadsheet control as well once 4.0 ships. View the screencast here: http://community.devexpress.com/blogs/aspnet/archive/2009/02/01/asp-net-dynamic-data-and-devexpress-grid.aspx. Please check it out and let Mehul know what you think!