Data Binding creates a link between a particular control to a specific column of a table in the database or to an entire table in the database. With ASP.NET data binding you can also bind any server control to the output of different methods and expressions.
On ASP.NET pages when we are doing databinding it is necessary to use the basic syntax for all expressions.
For example:
<%# EmpID %> This syntax is for a simple property.
<asp:ListBox datasource=’<%# firstArray %>’ runat=”server”> This syntax is for a collection.
<%# (emp.First Name + ” ” + emp.LastName ) %> This syntax is for an expression.
<%# GetSalary(EmpID) %> This syntax is for the result of method GetSalary().
If you are using a list control the following syntax is used:
<asp:Label runat=”server”
Text=’<%# Container.DataItem(“EmployeeName”) %>’
If you are using a RadioButtonList control to bind data then the syntax is:
<html>
<body><form runat=”server”>
<asp:RadioButtonList runat=”server” />
</form></body>
</html>
In multiple data bound Values in a Hyperlink Control with a GridView:
<form runat=”server”>
<asp:SqlDataSource runat=”server”
ConnectionString=”server=localhost;database=Northwind;uid=x;pwd=y”
SelectCommand=”SELECT ProductID, ProductName, QuantityPerUnit,
UnitPrice, UnitsInStock, Discontinued FROM Products” />
<asp:GridView DataSourceID=”datasource1″ runat=”server” />
</form>
If one wants to navigate between the fields then the syntax is:
DataNavigateUrlFields=”ProductID,SupplierID,ProductType”
In the following example, the code below uses a feature to provide a hyperlink that contains two values, both extracted from the current row of the employees table, for the href attribute:
<asp:SqlDataSource runat=”server”
SelectCommand=”SELECT EmpID, CompanyName, City FROM employees”/>
<asp:GridView DataSourceID=”datasource1″ runat=”server”
AutoGenerateColumns=”False”>
<Columns>
<asp:BoundField DataField=”EmpID” HeaderText=”BoundField” />
<asp:HyperLinkField runat=”server”
DataTextField=”employeeName”
DataNavigateUrlFields=”EmpID,City”
DataNavigateUrlFormatString=
“http://yoursite.com/showemployee.aspx?id={0}&city={1}” />
</Columns>
</asp:GridView>
The resulting value for the href attribute will be something like this:
“http://yoursite.com/showemployee.aspx?id=00123&city=Mumbai”
In the above example city of the employee is “Mumbai” and employee id is “00123”.
Databinding simplifies applications; and with less code a fast execution is done. .Net helps the programmer by reducing his/her work and time spent coding a data abstraction layer.

