Differences Between......

  • Thread starter Thread starter rn5a
  • Start date Start date
R

rn5a

Assuming that a DataGrid gets populated by a database column named
RegDate using a DataSet, what's the difference between

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

&

<%# Container.DataItem("RegDate") %>

If I am not wrong, the former can be used to format the output like
for e.g.

<%# DataBinder.Eval(Container.DataItem, "RegDate", "{0:d}") %>
 
Assuming that a DataGrid gets populated by a database column named
RegDate using a DataSet, what's the difference between

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

&

<%# Container.DataItem("RegDate") %>

If I am not wrong, the former can be used to format the output like
for e.g.

<%# DataBinder.Eval(Container.DataItem, "RegDate", "{0:d}") %>

The Eval method uses reflection to read the "RegDate" item from the
Container.DataItem object, so the result is the same.

You can use formatting when reading the value directly also:

<%# String.Format("{0:d}", Container.DataItem("RegDate")) %>
 
And DataBinder.Eval is a performance hit. As Göran says, it uses reflection
to determine the type, and reflection is a more intensive activity. If you
can avoid using the Eval method, do it as it will help boost performance of
your web app slightly.
 
Back
Top