|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Bind to Data in a Templated Control
The, , and Web server controls use templates to display data and to retrieve user input to insert, update, or delete data. In addition, you can use templates with the and controls to customize data layout.
You can bind a templated control to a data source control such as theor control by setting the templated control's DataSourceID property to the ID of the data source control. You can then use the Eval and Bind functions within the template to bind to data from the data source. For more information, see .
To bind a control to data using templates
Add a data source control such as the SqlDataSource control to the page, as in the following example:
Add a control that supports templates, such as the ASP.NET FormView control.
Set the templated control's DataSourceID property to the ID of the data source control from Step 1, as in this example:
<asp:FormView ID="FormView1" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" Runat="server"> </asp:FormView>
Add templates to the templated control and populate them with controls and markup.
To display data, use the Eval function as a property setting and reference the bound data field. In templates used to insert or edit data, use the Bind function to reference the data bound field, as shown in the following example:
Each Web server control supports different templates. For example, the Repeater control supports anand an to display data using alternating controls, styles, and markup. For details on Web server controls and supported templates, see .