DynamicControl Class
Updated: July 2008
Displays the content that is defined for the field in templated data-bound controls, using ASP.NET Dynamic Data features.
Assembly: System.Web.DynamicData (in System.Web.DynamicData.dll)
The DynamicControl control is used by templated data-bound controls, such as FormView or ListView, to display a data field that uses ASP.NET Dynamic Data features in a custom page. You can also use a DynamicControl control in a TemplateField field of a GridView or a DetailsView control.
The DynamicControl control provides functionality that is similar to that of the DynamicField field. However, because the DynamicControl control is only used inside templates, it gives you more flexibility in controlling how the data is displayed since you can add other HTML elements around the field. When you use a DynamicControl control, you can take advantage of the following Dynamic Data features:
•Automatically rendering the proper control for a field by using field templates, based on the data type. The field templates can be globally modified for the entire application.
•Providing built-in data validation based on the database schema. You can also add validation types by customizing the data model.
•Customizing data rendering for individual fields by using attributes in the data model or by using the P:System.Web.DynamicData.DynamicField.UIHint property.
To specify the field to display in a DynamicControl control, set the DataField property to the field name. You can apply a custom formatting string to the field value by setting the DataFormatString property. By default, the formatting string is applied to field values only when the data-bound control is in read-only mode. To apply the formatting string to values displayed while the data-bound control is in edit mode, set the ApplyFormatInEditMode property to true. If a field value is a null reference (Nothing in Visual Basic), you can display a custom caption by setting the NullDisplayText property. The DynamicControl control can also automatically convert empty string ("") field values to null values by setting the ConvertEmptyStringToNull property to true.
The DynamicControl control supports different display modes. To specify the mode in which to display the DynamicControl control, set the Mode property. The following table shows the different modes.
You can hide a DynamicControl control in a data-bound control by setting the Visible property to false.
See a run-time code example of this feature: Run.
The following example demonstrates how to use the DynamicControl control in a ListView control to display, insert, delete and edit values from a database table. It is important to notice that in order to make the insert operation to work, the IsDbGenerated property of the rowguid and ModifiedDate columns are set to true.
- AspNetHostingPermission
for operating in a hosted environment. Security action: LinkDemand. Associated enumeration: AspNetHostingPermissionLevel.Minimal
- AspNetHostingPermission
for operating in a hosted environment. Security action: InheritanceDemand. Associated enumeration: AspNetHostingPermissionLevel.Minimal
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.