This documentation is archived and is not being maintained.

IBindableTemplate Interface

Provides a way for ASP.NET data-bound controls, such as DetailsView and FormView, to automatically bind to an ASP.NET data source control within templated content sections.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public interface IBindableTemplate extends ITemplate

The IBindableTemplate interface provides a way for ASP.NET data-bound controls, such as DetailsView, GridView, and FormView, to bind to data supplied by an ASP.NET data source control, such as ObjectDataSource or SqlDataSource, when the data-bound control includes templated content.


Page developers do not implement the IBindableTemplate interface. Developers creating custom data-bound controls might manipulate IBindableTemplate objects in implementations of the PerformDataBinding and ExtractRowValues methods, but do not implement their own IBindableTemplate objects.

Data-bound controls such as GridView typically are aware of their child control trees, and can therefore bind values to them, extract values from them, and pass these values between the data-bound control and a data source control whenever data binding occurs. However, when a page developer defines templated content for a data-bound control, the child controls within the template are not visible to the parent data-bound control: the parent can render the child content (because controls effectively render themselves), but it cannot extract the values of these child controls to pass to an associated data source control's update, insert, or delete operation. In data-binding scenarios, templated content is opaque to a parent data-bound control. The Bind syntax makes it possible for the data-bound control to extract the values from a control data-bound inside an IBindableTemplate instance.

The data binding can be one-way or two-way. (These binding directions are defined by the BindingDirection enumeration.) One-way data binding is any data binding performed in an outbound direction, from data source control to data-bound control; for example, any data-reading scenario involves one-way data binding. For one-way data binding, you can use one-way data binding syntax (<%# Eval("fieldname") %>) inside templated content, and do not need to use two-way ASP.NET data-binding syntax. Two-way data-binding describes data-binding in the inbound direction, from the data-bound control to the data source control. Automatic edit, insert, and delete scenarios using ASP.NET data-bound and data source controls are two-way data-binding scenarios. These scenarios use two-way data-binding expressions (<%# Bind("fieldname") %>). The IBindableTemplate interface and the ASP.NET infrastructure support automatic, declarative, two-way data binding between ASP.NET data source controls and templated content. For more information about ASP.NET data-binding expressions and syntax, see Binding to Databases and Data-Binding Expressions Overview.

Templated content for data-bound controls is most often defined declaratively. The following table describes the processes most commonly used to bind templated data to data-bound controls.

Data-bound control



The data-bound control is bound to data using the DataSourceID property of the data source control, and the templated content is defined in an ItemTemplate, EditItemTemplate or InsertItemTemplate property.


The data-bound control is bound to data using the DataSourceID property of the data source control, and the templated content is defined in an ItemTemplate or EditItemTemplate property. The GridView control does not support an insert operation.


The data-bound control is bound to data using the DataSourceID property, and the templated content is defined in an ItemTemplate, InsertItemTemplate, or EditItemTemplate property, or in a TemplateField object.

The DataList and Repeater controls do not support automatic two-way data-binding scenarios.

ASP.NET implicitly creates an IBindableTemplate object when templated content that binds to an ASP.NET data source control within the template is parsed. Specifically, the ASP.NET parser creates an instance of the CompiledBindableTemplateBuilder class when it parses templated content that uses ASP.NET data-binding syntax and contains ASP.NET Web server controls that support data binding. These ASP.NET sever controls are marked by the BindableAttribute attribute.

The IBindableTemplate interface defines one method, ExtractValues. This method is defined for two-way data binding, so that a data-bound control can automatically extract name/value pairs from templated content and pass the pairs to a data source control at run time. For automatic data binding to succeed, the field names extracted from the templated content by the ExtractValues method must match parameter names in an associated data source control. Control developers call the ExtractValues method explicitly only within their implementations of ExtractRowValues or some other similar method of a custom data-bound control.

The following code example demonstrates how a FormView control can declaratively define templated content, bind to data provided by a SqlDataSource control, and display and edit existing records. The ASP.NET parser parses the templated content and creates an IBindableTemplate object at run time that is able to bind values from the SqlDataSource control to the data-binding areas defined in the template by both one-way ASP.NET data-binding syntax (<%# Eval("fieldname") %>) and two-way data-binding syntax (<%# Bind("fieldname") %>).

Security noteSecurity Note:

This control has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0