Tag Archive | Eval

Data Binding

There will come the time in every web application’s lifetime when it needs to display data. That data will be displayed in ASP.NET controls, but first they need to be bound to that control correctly. In this post we will consider the ways to do so.

There are two types of data-binding: Single-Value Binding and Repeated-Value Binding. Consider the former first.

To bind data to an ASP.NET control which supports it, you use the <%# %> delimiters in the property you want to bind to the data. This happens in the .aspx page, not in the code-behind. Between these delimiters, only valid data binding syntax can occur, for example:

protected string GetUserName()
{
     return User.Identity.Name;
}
<asp:TextBox runat=”server” Text=’<%#GetUserName()%>’/>

Read More…