TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

DataBinder.Eval versus Explicit Casting

As a regular DataBinder.Eval() user, now I feel a little bit guilty after reading this KB article, and I'm curious how many ASP.NET developers use explicit casting on a regular basis. Drop me a line and let me know.

Let's say you are binding to a DataSet. This...

<%# ((System.Data.DataRowView)Container.DataItem)["au_id"] %>

...is significantly faster than this...

<%# DataBinder.Eval(Container.DataItem, "au_id") %>

 

The DataBinder.Eval method uses reflection to evaluate the arguments that are passed in and to return the results. If you have a table that has 100 rows and 10 columns, you call DataBinder.Eval 1,000 times if you use DataBinder.Eval on each column. Your choice to use DataBinder.Eval is multiplied 1,000 times in this scenario. Limiting the use of DataBinder.Eval during data binding operations significantly improves page performance.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt05.asp


Digg!

posted on Sunday, March 06, 2005 1:45 PM

Feedback

# Adding Links to Blog Articles 6/24/2007 4:10 PM Colin Bowern

So you have figured out what you want to do with your spiffy new Community Server theme. You are thinking