.NETGURU
System.Format... vs. Databinder.Eval
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.


Ahmed, Salman
What is the syntax to display a integer and varchar using System.Format?

I heard it is much faster than Databinder.Eval?

Reply to this message...
 
    
Susan Warren
I'll add my 2 cents on this, if you don't mind. I'd be surpised if
"much faster" is really fast enough to be meaningful in most
applications. Yes, DataBinder.Eval uses reflection during databinding,
but if you are output-caching your pages (you should if you can) this is
one-time hit of *milliseconds* amortized over hundreds or thousands of
requests to the page. What you trade for those few milliseconds of
extra performance is cleaner, more maintainable code. Might be worth
considering when you calculate the cost of "optimizing."

That said, here's the code -- in both cases the field value is
substituted for the "{0}" token. Here's a C# example that formats the
Price field from my DataReader as currency. The ":c" specifies the
currency format.

Formatting with DataBinder.Eval() -- optional 3rd param is a format
string:

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

Formatting without DataBinder.Eval(). Note that the type of a single
row of data from a DataReader is System.Data.Common.DbDataRecord. For
DataSet, it's System.Data.DataRowView. For other data types, it's
something else. The point is that this approach demands that the
developer know a fair bit about the data object she is binding to.

    <%# String.Format("{0:c}",
((System.Data.Common.DbDataRecord)Container.DataItem)["Price"]) %>

There's a ton of information about String.Format and format string in
the docs. The same format strings work in DataBinder.Eval too.

Hth
Susan

-----Original Message-----
From: Ahmed, Salman [mailto:Click here to reveal e-mail address]=20
Sent: Monday, January 21, 2002 6:18 AM
To: aspngspeed
Subject: [aspngspeed] System.Format... vs. Databinder.Eval

What is the syntax to display a integer and varchar using System.Format?

I heard it is much faster than Databinder.Eval?

| [aspngspeed] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngspeed.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
 
System.ComponentModel.Container
System.Data.Common.DbDataRecord
System.Data.DataRowView
System.Data.DataSet
System.String
System.Web.UI.DataBinder




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification