DataBinder.Eval Container.DataItem Performance Asp.Net

Using DataBinder.Eval Container.DataItem Method Slow Down The Performance Of Asp.Net Web Applications noticeably.

DataBinder.Eval Container.DataItem Performance

It is mentioned in MSDN site as -

"Because this method performs late-bound evaluation, using reflection at run time, it can cause performance to noticeably slow compared to standard ASP.NET data-binding syntax."

So one should avoid using this method as much as possible.


We use DataBinder.Eval method quite frequently in controls like GridView, Detailsview, DataList or Repeater to evaluate data binding expressions at run time because of simplicity like i used for Running Total in GridView.

decimal rowTotal = Convert.ToDecimal
              (DataBinder.Eval(e.Row.DataItem, "Amount"));

Or in General context
<%# DataBinder.Eval (Container.DataItem, "Price") %>


Now as Eval method is performance hungry we can avoid using it by writing code like mentioned below.

<%# ((DataRowView)Container.DataItem)["FirstName"] %>

Casting Container.DataItem as DataRowView explicitly performs better then Using Eval method.


If you like this post than join us or share

3 comments:

Rick Strahl said...

Eh, have you actually done any profiling on this? DataBinder.Eval does Reflection based binding yes, but so does just about everything else in ASP.NET that is using databound controls. Unless you're writing your own loops with <%= %> expressions or creating HTML with hardcoded HTML, your perf will always hit Reflection.

The question is how much impact does this really have. In my testing of typical pages the impact is minimal and not enough to worry about unless you're displaying hundreds or thousands of rows of data (which you shouldn't do anyway). Typical data controls only display paged views with a few records displaying of a larger view and for that late binding slowdowns are minimal.

Changing that I'd easily call "premature optimization".

+++ Rick ---


adonet dude said...

Cool! I didn't know that you can use it like that!


thanks for sharing


Anonymous said...

Thank you for great article


Find More Articles