473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Container.DataItem

What's the difference between

<%# DataBinder.Eval(Container.DataItem,"LastName") %>

&

<%# Container.DataItem("LastName") %>

Thanks

Sep 24 '07 #1
6 15814
On Sep 24, 8:51 am, r...@rediffmail.com wrote:
What's the difference between

<%# DataBinder.Eval(Container.DataItem,"LastName") %>

&

<%# Container.DataItem("LastName") %>

Thanks
DataBinder.Eval is a helper function to evaluate data, and it use
reflection (late binding) to find right property in your item. You can
display data without using DataBinder.Eval, but you need to cast
Container.DataItem to the right type.

Note: Because DataBinder.Eval performs late-bound evaluation, using
reflection at run time, it can cause performance to noticeably slow
compared to explicit casting.

Sep 24 '07 #2
I used to advocate explicit casting in this newsgroup a while ago. There was
a strong opposition to it from quite experienced developers claiming that
the performance gain is not that significant comparing with the advantages
of using Eval. The major one is that with Eval you can change your
datasource without touching your databinding expressions. I can hear this
argument very well.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
On Sep 24, 8:51 am, r...@rediffmail.com wrote:
>What's the difference between

<%# DataBinder.Eval(Container.DataItem,"LastName") %>

&

<%# Container.DataItem("LastName") %>

Thanks

DataBinder.Eval is a helper function to evaluate data, and it use
reflection (late binding) to find right property in your item. You can
display data without using DataBinder.Eval, but you need to cast
Container.DataItem to the right type.

Note: Because DataBinder.Eval performs late-bound evaluation, using
reflection at run time, it can cause performance to noticeably slow
compared to explicit casting.

Sep 24 '07 #3
On Sep 24, 2:13 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Sep 24, 8:51 am, r...@rediffmail.com wrote:
What's the difference between
<%# DataBinder.Eval(Container.DataItem,"LastName") %>
&
<%# Container.DataItem("LastName") %>
Thanks

DataBinder.Eval is a helper function to evaluate data, and it use
reflection (late binding) to find right property in your item. You can
display data without using DataBinder.Eval, but you need to cast
Container.DataItem to the right type.

Note: Because DataBinder.Eval performs late-bound evaluation, using
reflection at run time, it can cause performance to noticeably slow
compared to explicit casting.
Alexey, could you please show some examples of what you have
explained? Sorry I couldn't exactly follow the difference.

Thanks to both of you....

Sep 24 '07 #4
On Sep 24, 10:24 am, r...@rediffmail.com wrote:
On Sep 24, 2:13 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:


On Sep 24, 8:51 am, r...@rediffmail.com wrote:
What's the difference between
<%# DataBinder.Eval(Container.DataItem,"LastName") %>
&
<%# Container.DataItem("LastName") %>
Thanks
DataBinder.Eval is a helper function to evaluate data, and it use
reflection (late binding) to find right property in your item. You can
display data without using DataBinder.Eval, but you need to cast
Container.DataItem to the right type.
Note: Because DataBinder.Eval performs late-bound evaluation, using
reflection at run time, it can cause performance to noticeably slow
compared to explicit casting.

Alexey, could you please show some examples of what you have
explained? Sorry I couldn't exactly follow the difference.

Thanks to both of you....- Hide quoted text -

- Show quoted text -
Here's a good article about that difference
http://odetocode.com/Articles/278.aspx

DataItem returns a reference to an object, and to return a value in
the proper type you need to cast it (especially for C#). Maybe it
makes no sense when we are talking just about simple strings but it
can be useful when you have some casting, e.g. show an integer as a
currency, etc.

DataBinder.Eval allows to avoid using casts because it finds
dynamically a property and its type by the name at runtime.

Sep 24 '07 #5
I agree. I've heard that same argument (about performance) from Nikhil
Kothari himself.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:OU**************@TK2MSFTNGP05.phx.gbl...
>I used to advocate explicit casting in this newsgroup a while ago. There
was a strong opposition to it from quite experienced developers claiming
that the performance gain is not that significant comparing with the
advantages of using Eval. The major one is that with Eval you can change
your datasource without touching your databinding expressions. I can hear
this argument very well.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
>On Sep 24, 8:51 am, r...@rediffmail.com wrote:
>>What's the difference between

<%# DataBinder.Eval(Container.DataItem,"LastName") %>

&

<%# Container.DataItem("LastName") %>

Thanks

DataBinder.Eval is a helper function to evaluate data, and it use
reflection (late binding) to find right property in your item. You can
display data without using DataBinder.Eval, but you need to cast
Container.DataItem to the right type.

Note: Because DataBinder.Eval performs late-bound evaluation, using
reflection at run time, it can cause performance to noticeably slow
compared to explicit casting.


Sep 24 '07 #6
On Sep 24, 5:25 pm, "Teemu Keiski" <jot...@aspalliance.comwrote:
I agree. I've heard that same argument (about performance) from Nikhil
Kothari himself.

--
Teemu Keiski
AspInsider, ASP.NET MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net

"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote in
messagenews:OU**************@TK2MSFTNGP05.phx.gbl. ..
I used to advocate explicit casting in this newsgroup a while ago. There
was a strong opposition to it from quite experienced developers claiming
that the performance gain is not that significant comparing with the
advantages of using Eval. The major one is that with Eval you can change
your datasource without touching your databinding expressions. I can hear
this argument very well.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Alexey Smirnov" <alexey.smir...@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
On Sep 24, 8:51 am, r...@rediffmail.com wrote:
What's the difference between
><%# DataBinder.Eval(Container.DataItem,"LastName") %>
>&
><%# Container.DataItem("LastName") %>
>Thanks
DataBinder.Eval is a helper function to evaluate data, and it use
reflection (late binding) to find right property in your item. You can
display data without using DataBinder.Eval, but you need to cast
Container.DataItem to the right type.
Note: Because DataBinder.Eval performs late-bound evaluation, using
reflection at run time, it can cause performance to noticeably slow
compared to explicit casting.- Hide quoted text -

- Show quoted text -
My quote regarding performance was from here
http://msdn2.microsoft.com/en-us/library/4hx47hfe.aspx

Sep 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: az bij | last post by:
Hi, I have a dataset bound to a repeater and want to place some logic in my ascx file. I want to display an image link if and only if an image is available. I have tried without success...
1
by: Mike P | last post by:
I'm having trouble with C# syntax for Container.DataItem. This is the VB version. CAn anybody help me out with the syntax? <asp:DataList runat="server" id="dlResults" Font-Name="Verdana"...
0
by: Lauchlan M | last post by:
Hi In my aspx page HTML I have <a href='<%# DataBinder.Eval(Container.DataItem, "Name") %>'> <%# DataBinder.Eval(Container.DataItem, "Name") %> I am trying to create a hyperlink to...
1
by: anony | last post by:
Hi, I would like to find out if it's possible to check the value of a Container.DataItem inside the Datagrid's <ItemTemplate> tag .... based on it's value, I would to either output it or output...
5
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
4
by: hsomob1999 | last post by:
I have a class, lets call it Schmuck. It has 2 public properties Name (string) and active (boolean). When I bind to a Repeater, like so: <%#container.dataitem("Name")%> i get the following error:...
2
by: Antony | last post by:
Hello, in my aspx.file I have this code inside a datagrid: <asp:TemplateColumn HeaderText="Picture"> <ItemTemplate> <asp:Image id="Image1" runat="server" ImageUrl='upload/<%#...
0
by: John Davis | last post by:
Hi all, hope you are well. I would like to know if I can access the strongly typed properties of my datatable when binding through the ObjectDataSource object. I am currently creating some...
0
by: John Davis | last post by:
Hi all, hope you are well.(not sure if this posted the first time) I would like to know if I can access the strongly typed properties of my datatable when binding through the ObjectDataSource...
3
by: alberthung01 | last post by:
Hi all, I try to use Container.DataItem() in my DataGrid's ItemTemplate. Somewhere it works fine. eg.<input type=checkbox id='cb_select_<%# Container.DataItem("TAG_ID") %>' value='<%#...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.