views:

58

answers:

2

When creating a website using Asp.Net and using controls such as the ListView is it good practice to use the "Eval" command or should there be a literal and the data populated in the databind event?

+1  A: 

Depends on the items you want to bind. Do they contain all necessary information for display? If yes, use Eval. If no, and you need to look up additional infomation in a dictionary or something like this, then the DataBound Event would be the place to use.

I've found out, that I usually use a DataBind event for bind classes that come from a Linq-To-SQL mapper. If I'm free in creating my own container class, containing all properties that are desired for display, I only use the Eval() thing. I guess it depends how resourceful the lookup of additional information is. Please keep in mind, that it is bad practise to use a LinqDataContext inside the DataBound-event.

citronas
+2  A: 

Depends if you want to write the data back on an update event in which case databind. If you only want to read that data you can use Bind() or Eval(), having said that Eval() uses reflection so there will be performance overhead there

Nick Allen - Tungle139
Can you post a reference for your statement, that Eval uses reflection?
citronas
In ASP.Net 3.5 unleashed, it states that EVAL is inefficient in template columns as it uses reflection. It's a shortcut for Container.DataItem()
Nick Allen - Tungle139