Data-binding expressions

By vijeyashobana

When working with Databound controls, very often we are required to work with templates, may be they are ItemTemplates, EditItemTemplates, InsertItemTemplates etc.  In these situations usually we’ll use data-binding expressions.

There are 3 types of commonly used Data-binding expressions.

1. Type I – <%# Eval(”column_name”) %>

The above expression is a 2-way expression, meaning you can read/write values. Commonly used in TextBoxes.

<asp:TextBox text = ‘<%# Eval(”LastName”) %>

2. Type II – <%# Bind(column_name) %>

The above expression is a 1-way expression, meaning you can only read values. Commonly used in DropDownLists, Listboxes, labels.

<asp:DropDownList SelectedValue = <%# Bind(”LastName”) %>

3. Type III – <%# Function() || variable %>

Examples: <%# SomeMethod() %>

<%# firstName %>

<%# (firstname)+’ ‘+(lastname) %>

Reference: http://msdn.microsoft.com/en-us/library/ms178366(VS.80).aspx, http://bhaidar.net/cs/archive/2006/08/04/473.aspx

Tags: , ,

Leave a Reply