Differences Between......

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}") %>
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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")) %>
 
M

Mark Fitzpatrick

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top