DataBinding - DataList

Discussion in 'ASP .Net' started by Jim Heavey, May 24, 2004.

  1. Jim Heavey

    Jim Heavey Guest

    I have a book which shows that I can do Databinding to a control like the
    following:

    <asp:Label ID="lblScorecardCmntCategory" Runat="server" text='<%#
    Container.DataItem("Name") %>'></asp:Label>

    When I run this I get a error about, somthing about it was expecting a
    method, not a property. DataItem is a method, is it not? If I use the
    longer "eval" form, it works just fine, but I do not understand what I am
    doing wrong with this "version" of databinding.

    Can you clear up my confustion?
     
    Jim Heavey, May 24, 2004
    #1
    1. Advertising

  2. Jim Heavey

    Pete Wright Guest

    This would happen if the language you are using is C#. Replace
    DataItem("Name") with DataItem["Name"] since DataItem is an array and is
    referenced with square brackets in C#, instead of the curvy ones used in
    Visual Basic.

    Hope that helps,



    --
    --------------------------------------------------------
    Peter Wright (www.petewright.org)
    Author of ADO.NET Novice To Pro
    From Apress. www.apress.com (and 10
    other doorstops from Wrox)


    "Jim Heavey" <> wrote in message
    news:Xns94F353497F677JimHeaveyhotmailcom@207.46.248.16...
    > I have a book which shows that I can do Databinding to a control like the
    > following:
    >
    > <asp:Label ID="lblScorecardCmntCategory" Runat="server" text='<%#
    > Container.DataItem("Name") %>'></asp:Label>
    >
    > When I run this I get a error about, somthing about it was expecting a
    > method, not a property. DataItem is a method, is it not? If I use the
    > longer "eval" form, it works just fine, but I do not understand what I am
    > doing wrong with this "version" of databinding.
    >
    > Can you clear up my confustion?
    >
     
    Pete Wright, May 24, 2004
    #2
    1. Advertising

  3. Jim Heavey

    Raterus Guest

    Container.DataItem("Name") may look like a method, but it is really just an indexed property. Which as you found out, you can't put there :)

    Some reason you don't want to use DataBinder.Eval(Container.DataItem, "Name") ?
    --Michael

    "Jim Heavey" <> wrote in message news:Xns94F353497F677JimHeaveyhotmailcom@207.46.248.16...
    > I have a book which shows that I can do Databinding to a control like the
    > following:
    >
    > <asp:Label ID="lblScorecardCmntCategory" Runat="server" text='<%#
    > Container.DataItem("Name") %>'></asp:Label>
    >
    > When I run this I get a error about, somthing about it was expecting a
    > method, not a property. DataItem is a method, is it not? If I use the
    > longer "eval" form, it works just fine, but I do not understand what I am
    > doing wrong with this "version" of databinding.
    >
    > Can you clear up my confustion?
    >
     
    Raterus, May 24, 2004
    #3
  4. Jim Heavey

    Jim Heavey Guest

    I was told (read in a book) that it was less efficient.
     
    Jim Heavey, May 24, 2004
    #4
  5. Jim Heavey

    Jim Heavey Guest

    When I use [] as you suggested, I get the following error (and yes, I was
    using C#)..

    Cannot apply indexing with [] to an expression of type 'object'
    <%# Container.DataItem["CMT1"]%>

    I know the book I was reading called it a method, so I just presumed that
    it was.

    So why does it not like this?
     
    Jim Heavey, May 24, 2004
    #5
    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. Ronald Frown

    Databinding a datalist within a panel

    Ronald Frown, Apr 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    339
    Teemu Keiski
    Apr 10, 2004
  2. caldera

    Databinding datalist problem.

    caldera, Apr 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    322
    caldera
    Apr 15, 2004
  3. Nevyn Twyll
    Replies:
    8
    Views:
    1,916
  4. jobs
    Replies:
    0
    Views:
    1,673
  5. Earl Teigrob
    Replies:
    1
    Views:
    420
    Shravan
    Mar 1, 2004
Loading...

Share This Page