Eval: Sometimes I like spagheti code
I just discovered some interesting features of the construct <%# Eval() %> . Eval function uses reflection to evaluate a property of a bound object. I have two classes Product and Category and I want to display the available products in a page, by using a data bound control. public class Product { public int ID; public string Name; public int Stock; public DateTime Date; public Category Category; } public class Category { public string Name; public DateTime Date; } In a data template ( ItemTemplate for sample ) I can use the Eval function like: 1. very simple evaluation without using formats <%# Eval("Name") %> - will output the name <%# Eval("Stock") %> - will output the stock ( ..and so on ) 2. using a format <%# Eval("Date","{0:yyyy MMM dd}") %> - for sample: 2009 Apr 06 <%# Eval("Stock","{0} items") %> - will output "10 items" if the stock is 10 3. Co