in

ASP.NET Weblogs

rbfigueira.net

All about .net stuff, Compact framework, framework.net and personal projects.

DataBinder (Pros and Cons)

DataBinder.Eval method saves you from writing complex expressions ;)

BUT, using this method does impose a performance penalty on your code, because all the work it does is late-bound. Ok, if we want the fastest possible code, you can replace calls to DataBinder.Eval with explicit casts.

For example:

<%# DataBinder.Eval(Container.DataItem, “myField”,“{0:c}”) %>

An equivalent expression using casts would be this:

<%# String.Format(“{0:c}”,(CType(Container.DataItem,DataRowView)(“myField”))) %>

Good ;)

Published Oct 19 2003, 01:54 PM by rbfigueira
Filed under:

Comments

 

Gilad said:

Didn't quite understand...
Why does explicit casting improve the speed of our code?
October 19, 2003 9:59 AM
 

rbfigueira said:

The important point here is that late-bound invocation is done solely off the run-time type of the invocation target and arguments.

When the type of an invocation target is Object, and the method being invoked is not a member of Object, the processing of an invocation expression does not occur until run time.

See this : ms-help://MS.VSCC/MS.MSDNVS/vbls7/html/vblrfVBSpec9_8_1.htm
October 20, 2003 8:42 AM

Leave a Comment

(required)  
(optional)
(required)  
Add