Sunday, June 29, 2008

ASP.NET data binding essentials

<%# %> Syntax

ASP.NET introduces a new declarative syntax, <%# %>. This syntax is the basis for using data binding in an .aspx page. All data binding expressions must be contained within these characters. The following list includes examples of simple data binding from multiple sources:

• Simple property (syntax for a customer):
<%# custID %>

• Collection (syntax for an order):
<asp:listbox id="List1" datasource="'<%#">' runat="server">

• Expression (syntax for a contact):
<%# ( customer.First Name + " " + customer.LastName ) %>

• Method result (syntax for the outstanding balance):
<%# GetBalance(custID) %>

In the preceding examples, the inline <%# %> tags indicate where the information from a specific data source is to be placed in the .aspx page. The following data binding example uses a TextBox Web server control: <asp:textbox id="txt" text=="<%# custID %>" runat=server />

For more information about data binding syntax, see the following .NET Framework Software Development Kit (SDK) documentation:
Data Binding Expression Syntax
http://msdn2.microsoft.com/en-us/library/bda9bbfx(vs.71).aspx

No comments: