开发者

Should we be using Eval or the Databind event?

开发者 https://www.devze.com 2022-12-24 13:56 出处:网络
When creating a website using Asp.Net and using controls such as the ListView is it go开发者_Python百科od practice to use the \"Eval\" command or should there be a literal and the data populated in th

When creating a website using Asp.Net and using controls such as the ListView is it go开发者_Python百科od practice to use the "Eval" command or should there be a literal and the data populated in the databind event?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消