.NETGURU
DataBinder.Eval alternative
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.


Yannick Smits
I heard I should avoid use of DataBinder.Eval because of it's late binding.
Now I'm trying to rewrite some code but not sure how. What I have is:

<%# DataBinder.Eval(Container.DataItem, "myDate", "{:D}" %>

I found a way to do the same without DataBinder.Eval but I think it is also late-binding. Can somebody confirm?:

<%# Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString("d MMM yyy") %>

Is this way better than the DataBinder.Eval method? Or should I use the ItemDataBound event in combination with the findcontrol
technique to get 30% performance gain?

Thanks,
Yannick Smits

Reply to this message...
 
    
Susan Warren
If you want avoid the reflection cost of DataBinder.Eval, try this:=20

<%# String.Format("{0:D}",((DataRowView)Container.DataItem)["myDate"])
%>

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 5:44 AM
To: aspngspeed
Subject: [aspngspeed] DataBinder.Eval alternative

I heard I should avoid use of DataBinder.Eval because of it's late
binding.
Now I'm trying to rewrite some code but not sure how. What I have is:

<%# DataBinder.Eval(Container.DataItem, "myDate", "{:D}" %>

I found a way to do the same without DataBinder.Eval but I think it is
also late-binding. Can somebody confirm?:

<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is this way better than the DataBinder.Eval method? Or should I use the
ItemDataBound event in combination with the findcontrol
technique to get 30% performance gain?

Thanks,
Yannick Smits

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

Reply to this message...
 
    
Yannick Smits
Thanks Susan, but what about:
<%# Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString("d MMM yyy") %>

Is it slow too? Or is it just the DataBinder.Eval that is slow?

Thanks,
Yannick Smits

"Susan Warren" <Click here to reveal e-mail address> wrote in message news:452582@aspngspeed...

If you want avoid the reflection cost of DataBinder.Eval, try this:

<%# String.Format("{0:D}",((DataRowView)Container.DataItem)["myDate"])
%>

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 5:44 AM
To: aspngspeed
Subject: [aspngspeed] DataBinder.Eval alternative

I heard I should avoid use of DataBinder.Eval because of it's late
binding.
Now I'm trying to rewrite some code but not sure how. What I have is:

<%# DataBinder.Eval(Container.DataItem, "myDate", "{:D}" %>

I found a way to do the same without DataBinder.Eval but I think it is
also late-binding. Can somebody confirm?:

<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is this way better than the DataBinder.Eval method? Or should I use the
ItemDataBound event in combination with the findcontrol
technique to get 30% performance gain?

Thanks,
Yannick Smits

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

Reply to this message...
 
    
Susan Warren
This is essentially the same as the string I sent you, speed-wise. No
reflection here, which is the costly part of DataBinder.Eval. But the
efficiency may be a bit less than perfect. Your line of code does the
following:=20

    1. casts the dataitem to type DataRowView:
(DataRowView)Container.DataItem)
    2. accesses ["myDate"] via a named accessor. This return an
object
    3. does a .ToString(format) on the object

up to this point it's equivalent to the String.Format variant I sent
below.

    4. THEN your expression does a Covert.ToDateTime() --=20

why #4??? Are you after a value of type DateTime? If so, why not:

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

And skip the conversion to/from string altogether?

hth.
Susan

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 7:10 AM
To: aspngspeed
Subject: [aspngspeed] Re: DataBinder.Eval alternative

Thanks Susan, but what about:
<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is it slow too? Or is it just the DataBinder.Eval that is slow?

Thanks,
Yannick Smits

"Susan Warren" <Click here to reveal e-mail address> wrote in message
news:452582@aspngspeed...

If you want avoid the reflection cost of DataBinder.Eval, try this:

<%# String.Format("{0:D}",((DataRowView)Container.DataItem)["myDate"])
%>

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 5:44 AM
To: aspngspeed
Subject: [aspngspeed] DataBinder.Eval alternative

I heard I should avoid use of DataBinder.Eval because of it's late
binding.
Now I'm trying to rewrite some code but not sure how. What I have is:

<%# DataBinder.Eval(Container.DataItem, "myDate", "{:D}" %>

I found a way to do the same without DataBinder.Eval but I think it is
also late-binding. Can somebody confirm?:

<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is this way better than the DataBinder.Eval method? Or should I use the
ItemDataBound event in combination with the findcontrol
technique to get 30% performance gain?

Thanks,
Yannick Smits

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

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

Reply to this message...
 
    
Yannick Smits

I think point 3 and 4 should be shifted.
-I get back a string format from my SQL Server (I couldn't get the DateTime format to work for a temporary table in a stored
procedure, only the nvarchar).
-Than I convert it to a DateTime format.
-Than I reconvert it to a string in the ("d MMM yyy") format.

It would be faster to get a DateTime from the SQL Server but I can't get that to work. The error that I get when I try this is:
"Cannot specify a column width on data type datetime."
This occurs when I try to fill the dataset like this:
myDataAdapter.Fill(myDataSet, "Guestbook");

hope this is not too off-topic..

Thanks,
Yannick Smits

"Susan Warren" <Click here to reveal e-mail address> wrote in message news:452626@aspngspeed...

This is essentially the same as the string I sent you, speed-wise. No
reflection here, which is the costly part of DataBinder.Eval. But the
efficiency may be a bit less than perfect. Your line of code does the
following:

1. casts the dataitem to type DataRowView:
(DataRowView)Container.DataItem)
2. accesses ["myDate"] via a named accessor. This return an
object
3. does a .ToString(format) on the object

up to this point it's equivalent to the String.Format variant I sent
below.

4. THEN your expression does a Covert.ToDateTime() --

why #4??? Are you after a value of type DateTime? If so, why not:

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

And skip the conversion to/from string altogether?

hth.
Susan

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 7:10 AM
To: aspngspeed
Subject: [aspngspeed] Re: DataBinder.Eval alternative

Thanks Susan, but what about:
<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is it slow too? Or is it just the DataBinder.Eval that is slow?

Thanks,
Yannick Smits

"Susan Warren" <Click here to reveal e-mail address> wrote in message
news:452582@aspngspeed...

If you want avoid the reflection cost of DataBinder.Eval, try this:

<%# String.Format("{0:D}",((DataRowView)Container.DataItem)["myDate"])
%>

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 5:44 AM
To: aspngspeed
Subject: [aspngspeed] DataBinder.Eval alternative

I heard I should avoid use of DataBinder.Eval because of it's late
binding.
Now I'm trying to rewrite some code but not sure how. What I have is:

<%# DataBinder.Eval(Container.DataItem, "myDate", "{:D}" %>

I found a way to do the same without DataBinder.Eval but I think it is
also late-binding. Can somebody confirm?:

<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is this way better than the DataBinder.Eval method? Or should I use the
ItemDataBound event in combination with the findcontrol
technique to get 30% performance gain?

Thanks,
Yannick Smits

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

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

Reply to this message...
 
    
Susan Warren
Oops, yep, you're right. So your code and mine are essentially
equivalent.

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 8:01 AM
To: aspngspeed
Subject: [aspngspeed] Re: DataBinder.Eval alternative

I think point 3 and 4 should be shifted.
-I get back a string format from my SQL Server (I couldn't get the
DateTime format to work for a temporary table in a stored
procedure, only the nvarchar).
-Than I convert it to a DateTime format.
-Than I reconvert it to a string in the ("d MMM yyy") format.

It would be faster to get a DateTime from the SQL Server but I can't get
that to work. The error that I get when I try this is:
"Cannot specify a column width on data type datetime."
This occurs when I try to fill the dataset like this:
myDataAdapter.Fill(myDataSet, "Guestbook");

hope this is not too off-topic..

Thanks,
Yannick Smits

"Susan Warren" <Click here to reveal e-mail address> wrote in message
news:452626@aspngspeed...

This is essentially the same as the string I sent you, speed-wise. No
reflection here, which is the costly part of DataBinder.Eval. But the
efficiency may be a bit less than perfect. Your line of code does the
following:

1. casts the dataitem to type DataRowView:
(DataRowView)Container.DataItem)
2. accesses ["myDate"] via a named accessor. This return an
object
3. does a .ToString(format) on the object

up to this point it's equivalent to the String.Format variant I sent
below.

4. THEN your expression does a Covert.ToDateTime() --

why #4??? Are you after a value of type DateTime? If so, why not:

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

And skip the conversion to/from string altogether?

hth.
Susan

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 7:10 AM
To: aspngspeed
Subject: [aspngspeed] Re: DataBinder.Eval alternative

Thanks Susan, but what about:
<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is it slow too? Or is it just the DataBinder.Eval that is slow?

Thanks,
Yannick Smits

"Susan Warren" <Click here to reveal e-mail address> wrote in message
news:452582@aspngspeed...

If you want avoid the reflection cost of DataBinder.Eval, try this:

<%# String.Format("{0:D}",((DataRowView)Container.DataItem)["myDate"])
%>

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Friday, August 03, 2001 5:44 AM
To: aspngspeed
Subject: [aspngspeed] DataBinder.Eval alternative

I heard I should avoid use of DataBinder.Eval because of it's late
binding.
Now I'm trying to rewrite some code but not sure how. What I have is:

<%# DataBinder.Eval(Container.DataItem, "myDate", "{:D}" %>

I found a way to do the same without DataBinder.Eval but I think it is
also late-binding. Can somebody confirm?:

<%#
Convert.ToDateTime(((DataRowView)Container.DataItem)["myDate"]).ToString
("d MMM yyy") %>

Is this way better than the DataBinder.Eval method? Or should I use the
ItemDataBound event in combination with the findcontrol
technique to get 30% performance gain?

Thanks,
Yannick Smits

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

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

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

Reply to this message...
 
 
System.ComponentModel.Container
System.Convert
System.Data.DataRowView
System.DateTime
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