Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Container.DataItem

Reply
Thread Tools

Container.DataItem

 
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      09-24-2007
What's the difference between

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

&

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

Thanks

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      09-24-2007
On Sep 24, 8:51 am, (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-24-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On Sep 24, 8:51 am, (E-Mail Removed) 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.
>



 
Reply With Quote
 
rn5a@rediffmail.com
Guest
Posts: n/a
 
      09-24-2007
On Sep 24, 2:13 am, Alexey Smirnov <(E-Mail Removed)> wrote:
> On Sep 24, 8:51 am, (E-Mail Removed) 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....

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      09-24-2007
On Sep 24, 10:24 am, (E-Mail Removed) wrote:
> On Sep 24, 2:13 am, Alexey Smirnov <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Sep 24, 8:51 am, (E-Mail Removed) 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.

 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-24-2007
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" <(E-Mail Removed)> wrote in
message news:OUtMNIo$(E-Mail Removed)...
>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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
>> On Sep 24, 8:51 am, (E-Mail Removed) 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.
>>

>
>



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      09-24-2007
On Sep 24, 5:25 pm, "Teemu Keiski" <(E-Mail Removed)> wrote:
> 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" <(E-Mail Removed)> wrote in
> messagenews:OUtMNIo$(E-Mail Removed). ..
>
>
>
> >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" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed) oups.com...
> >> On Sep 24, 8:51 am, (E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments