Using Dynamic Data in ASP.NET Applications
ASP.NET Dynamic Data has the ability to infer at run time the appearance and behavior of data fields from the underlying database. It uses this information to select appropriate templates to render the data. Templates eliminate the need to redesign the UI every time that you want to display a table.
This topic describes the main scenarios for using ASP.NET Dynamic Data.
Enabling Dynamic Data for Individual Data-Bound Controls in Existing Web Applications
You can use Dynamic Data features in existing ASP.NET Web applications that do not use scaffolding by enabling Dynamic Data for individual data-bound controls. Dynamic Data provides the presentation and data layer support for rendering these controls. When you enable Dynamic Data for data-bound controls, you get the following benefits:
Setting default values for data fields. Dynamic Data enables you to provide default values at run time for fields in a data control.
Interacting with the database without creating and registering a data model. Data-bound controls that support Dynamic Data can interact with the database by using any data source, without scaffolding. This avoids having to configure a LINQ to SQL or Entity Framework data model and use the LinqDataSource and EntityDataSource controls.
Automatically validating the data that is entered by the user without writing any code.
When you use this approach, Dynamic Data performs all the tasks for accessing and rendering data. You must write a small amount of code, and you do have limited control over Dynamic Data operations.
You can enable dynamic behavior in ASP.NET data-bound controls by using methods in the DynamicDataExtensions class. For more information, see Walkthrough: Enabling Dynamic Data in ASP.NET Data-Bound Controls.
Creating Data-Driven Web Applications Using Scaffolding
Dynamic Data supports scaffolding, which can automatically generate UI to display and edit data. This approach lets you create a new data-driven Web application using little or no code. The application lets you customize the behavior of the application at both the presentation layer and the data layer.
ASP.NET Dynamic Data includes the following classes that help you use dynamic features in your pages:
These classes enable you to perform the following tasks:
Add dynamic behavior to individual data fields in ASP.NET data-bound controls such as the GridView and DetailsView controls. For more information, see How to: Add Dynamic Behavior to GridView and DetailsView Controls.
Add dynamic behavior to templated data-bound controls such as the ListView, FormView, and Repeater controls. By working with templates, you can have complete control over the layout and appearance of the data in the control. For more information, see How to: Add Dynamic Behavior to Templated Data-Bound Controls.
Customize data field appearance and behavior. You can customize the appearance and behavior of a data field as follows:
- By using the UIHint property or the UIHint property in page markup. For more information, see How to: Customize Data Field Appearance and Behavior in a Data-Bound Control.
By using the UIHintAttribute attribute in the data model. For more information, see Walkthrough: Customizing Data Field Appearance and Behavior in the Data Model.
If you use both, the markup and the data model approach, the markup approach takes precedence.
When you use this approach, Dynamic Data performs all the tasks that are required for accessing and rendering data. You must write a small amount of code, but you have full control over Dynamic Data operations. This approach cannot be used in existing Web applications that do not use scaffolding.
For more information, see Walkthrough: Creating a New Dynamic Data Web Site Using Scaffolding.
Using Dynamic Data in Existing Web Applications
You can use Dynamic Data features in a new or existing Web application by integrating the required scaffolding elements. This enables you to use your own Web organization, and not the predefined scaffolding, while fully utilizing the Dynamic Data features. This lets you take advantage of tested components and provides control over customization.
Integrating Dynamic Data in your own Web application provides the following benefits:
Adding dynamic behavior to data-bound controls, such as automatic validation and customized appearance and behavior of data fields. For more information, see How to: Add Dynamic Behavior to GridView and DetailsView Controls and How to: Add Dynamic Behavior to Templated Data-Bound Controls.
You can customize how users see and edit data fields by changing the default templates. Dynamic Data selects the appropriate templates based on the information that it infers from the data model.
You can create custom templates that define how data fields are rendered for display and for editing.
When you use this approach, Dynamic Data performs all the tasks that are required for accessing and rendering data. You have to write some code to integrate Dynamic Data behavior, but you have full control on Dynamic Data operations.
For more information, see Walkthrough: Adding Dynamic Data to Existing ASP.NET Web Sites.