|
| 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
|
|
|
| |
|
| |
| | |
| |
| 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
|
|
|
| |
|
|
| |
|
| |
| 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
|
|
|
| |
|
| |
|
| |
| 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
|
|
|
| |
|
| |
|
| |
| 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
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|