Friday, May 4, 2012

Displaying data with <%# %>, OnDataItemBound or use OnDataBinding in ASP.net?

This has been on my mind for years and I have seen both and used both in different projects the last 10 years. But which is better or preferred?

As an example consider a ListView which will bind to a poco called Employee which has properties Name and EmployedSince. The ListView will display the name of the employee as well as how long the user has been employed in years.

public class Employee
{
    public string Name { get; set; }
    public DateTime EmployedSince { get; set; }
}