DataList Question

Discussion in 'ASP .Net Web Controls' started by Steve, Aug 5, 2004.

  1. Steve

    Steve Guest

    Hi

    Please could someone suggest why this works :-

    <asp:DataList id="myDL" runat="server">
    <ItemTemplate>
    <%# DataBinder.Eval container.DataItem, "Filename") %>
    </ItemTemplate>
    </asp:DataList>

    and this doesn't :-

    <asp:DataList id="myDL" runat="server">
    <ItemTemplate>
    <%# Container.DataItem("Filename") %>
    </ItemTemplate>
    </asp:DataList>

    I get the following error msg in vis studio with the
    latter.

    'System.Web.UI.WebControls.DataListItem.DataItem' denotes
    a 'property' where a 'method' was expected

    Thanks for sharing your knowledge
    Steve
    Steve, Aug 5, 2004
    #1
    1. Advertising

  2. Steve

    Teemu Keiski Guest

    Hi,

    the first one uses late-binding, that is evaluates the expression at runtime
    (DataBinder.Eval is designed to locate the property and output its value as
    text). The other version uses early-bind way, so it must follow the exact
    rules for the programming language (you use C#?).

    To work the second way, you'd need to cast the Container.DataItem to its
    actual type, which depends on what you bind the DataList to (with dataReader
    System.Data.Common.DBDataRecord and with DataSet/DataTable/DataView it is
    System.Data.DataRowView), and then access the property like the programming
    language supposes.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke



    "Steve" <> wrote in message
    news:07e601c47ade$350142e0$...
    > Hi
    >
    > Please could someone suggest why this works :-
    >
    > <asp:DataList id="myDL" runat="server">
    > <ItemTemplate>
    > <%# DataBinder.Eval container.DataItem, "Filename") %>
    > </ItemTemplate>
    > </asp:DataList>
    >
    > and this doesn't :-
    >
    > <asp:DataList id="myDL" runat="server">
    > <ItemTemplate>
    > <%# Container.DataItem("Filename") %>
    > </ItemTemplate>
    > </asp:DataList>
    >
    > I get the following error msg in vis studio with the
    > latter.
    >
    > 'System.Web.UI.WebControls.DataListItem.DataItem' denotes
    > a 'property' where a 'method' was expected
    >
    > Thanks for sharing your knowledge
    > Steve
    Teemu Keiski, Aug 5, 2004
    #2
    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. Gönen EREN

    Datalist in Datalist How?

    Gönen EREN, Aug 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    396
    Gönen EREN
    Aug 22, 2003
  2. acko bogicevic

    DataList in DataList

    acko bogicevic, Nov 10, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,495
    acko bogicevic
    Nov 11, 2003
  3. Steve Lloyd
    Replies:
    1
    Views:
    685
    Rick Spiewak
    May 26, 2004
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,846
  5. Luis Esteban Valencia
    Replies:
    1
    Views:
    478
    John Saunders
    Jan 6, 2005
Loading...

Share This Page