Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
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...
Vote that this is a GOOD answer...
 
 
    
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...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
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...
Vote that this is a GOOD answer...
 
Open source windows
The Law Society’s guidelines on e-mail management
 
    
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...
Vote that this is a GOOD answer...
 
 
 
System.ComponentModel.Container
System.Convert
System.Data.DataRowView
System.DateTime
System.String
System.Web.UI.DataBinder




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734