Tuesday, February 16, 2010

What is Data Binding?

Data binding is one of those terms that states exactly what it is. It is a process of binding data to an ASP.NET 3.5 control. The data source that makes the most sense to bind is the data from a table in a database, but any kind of data can be bound using data binding. For example, we can bind values from items in an array or from a simple variable. Likewise, we can usefully bind data from a relational database or a single table.

On the ASP.NET side of the equation, the binding tag is simplicity itself. The tag is assigned to a control property. It has the following format:
<%# dataSource %>

The data source can be as simple as a function called in the C# portion of the application, or it may use a special ASP.NET function. For example:
<%# DataBinder.Eval(Container.DataItem, “FieldName”) %>

It is part of a larger data access application that uses a set of data binding tags employed with a Repeater control and multiple fields. If we prefer, we can use the shorter version that does not show the fuller object path:
<%# Eval(“FieldName”) %>

No comments:

Post a Comment