Container.DataItem

Discussion in 'ASP .Net' started by rn5a@rediffmail.com, Sep 24, 2007.

  1. Guest

    What's the difference between

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

    &

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

    Thanks
     
    , Sep 24, 2007
    #1
    1. Advertising

  2. On Sep 24, 8:51 am, 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 Smirnov, Sep 24, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > On Sep 24, 8:51 am, 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.
    >
     
    Eliyahu Goldin, Sep 24, 2007
    #3
  4. Guest

    On Sep 24, 2:13 am, Alexey Smirnov <> wrote:
    > On Sep 24, 8:51 am, 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, 2007
    #4
  5. On Sep 24, 10:24 am, wrote:
    > On Sep 24, 2:13 am, Alexey Smirnov <> wrote:
    >
    >
    >
    >
    >
    > > On Sep 24, 8:51 am, 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.
     
    Alexey Smirnov, Sep 24, 2007
    #5
  6. Teemu Keiski Guest

    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" <> wrote in
    message news:OUtMNIo$...
    >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" <> wrote in message
    > news:...
    >> On Sep 24, 8:51 am, 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.
    >>

    >
    >
     
    Teemu Keiski, Sep 24, 2007
    #6
  7. On Sep 24, 5:25 pm, "Teemu Keiski" <> 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" <> wrote in
    > messagenews:OUtMNIo$...
    >
    >
    >
    > >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" <> wrote in message
    > >news:...
    > >> On Sep 24, 8:51 am, 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
     
    Alexey Smirnov, Sep 24, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lauchlan M
    Replies:
    1
    Views:
    7,335
    Lauchlan M
    Oct 15, 2003
  2. Tom Lee
    Replies:
    2
    Views:
    857
    Chris Carter
    Dec 9, 2003
  3. Daniel

    Container.DataItem doubt

    Daniel, Dec 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    389
    Daniel
    Dec 16, 2003
  4. anony
    Replies:
    1
    Views:
    466
    =?Utf-8?B?QmFycnkgRm9ycmVzdA==?=
    Feb 19, 2004
  5. Joe Rattz
    Replies:
    2
    Views:
    641
    Robert Koritnik
    Sep 10, 2004
Loading...

Share This Page