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 nullNothingnullptra 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.
- ReadOnly
for display mode.This prevents the user from modifying the values of a record or a data field. It can be used in any of the templates.
- Edit
for edit mode.This enables users to update the values of an existing record. It is used in the edit template (typically called EditItemTemplate).
- Insert
for insert mode. This enables users to enter values for a new record. It is used in the insert template (typically called InsertItemTemplate).
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.