DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major")

Discussion in 'ASP .Net' started by Eric Newton, Apr 4, 2005.

  1. Eric Newton

    Eric Newton Guest

    Given databinding an array of System.Version types:

    Given that "SomeObject" type has a Version property:

    public class SomeObject
    {
    public Version Version { get; }
    public string Description { get; }
    }

    and I want to bind a list of them to a datagrid.

    DataGrid1.DataSource = someObjectList; // basically an array of "someobject"
    DataGrid1.DataBind();

    How does one utilize the DataBinder.Eval (and in asp.net v2.0, the Eval
    method) to get to the SomeObject.Version.Major property?

    (Assuming ALL that other stuff is Syntax proper, and so forth)

    --
    Eric Newton
    eric.at.ensoft-software.com
    www.ensoft-software.com
    C#/ASP.net Solutions developer
     
    Eric Newton, Apr 4, 2005
    #1
    1. Advertising

  2. Eric Newton

    Brock Allen Guest

    In your template:

    <asp:Repeater ...>
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "Version") %> is the version<br/>
    <%# DataBinder.Eval(Container.DataItem, "Description") %> is the description<br/>
    </ItemTemplate>
    </asp:Repeater>

    Container.DataItem is the "row" you're databinding to. The "row" can be any
    object, SomeObject in your case. DataBinder.Eval dynamicaly looks up on the
    first parameter the propery specified by the secon parameter and returns
    the string representation. this is used to fill in the Repeter's rendering.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Given databinding an array of System.Version types:
    >
    > Given that "SomeObject" type has a Version property:
    >
    > public class SomeObject
    > {
    > public Version Version { get; }
    > public string Description { get; }
    > }
    > and I want to bind a list of them to a datagrid.
    >
    > DataGrid1.DataSource = someObjectList; // basically an array of
    > "someobject" DataGrid1.DataBind();
    >
    > How does one utilize the DataBinder.Eval (and in asp.net v2.0, the
    > Eval method) to get to the SomeObject.Version.Major property?
    >
    > (Assuming ALL that other stuff is Syntax proper, and so forth)
    >
     
    Brock Allen, Apr 4, 2005
    #2
    1. Advertising

  3. Eric Newton

    Eric Newton Guest

    I was actually talking about the Version property's Major property...
    because the following doesn't work:

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

    I'm trying to find out if there's a different delimiter (besides the
    intuitive ".") to use to tell the Eval method to give me
    SomeObject.Version.Major

    --
    Eric Newton
    eric.at.ensoft-software.com
    www.ensoft-software.com
    C#/ASP.net Solutions developer

    "Brock Allen" <> wrote in message
    news:...
    > In your template:
    >
    > <asp:Repeater ...>
    > <ItemTemplate>
    > <%# DataBinder.Eval(Container.DataItem, "Version") %> is the version<br/>
    > <%# DataBinder.Eval(Container.DataItem, "Description") %> is the
    > description<br/>
    > </ItemTemplate>
    > </asp:Repeater>
    >
    > Container.DataItem is the "row" you're databinding to. The "row" can be
    > any object, SomeObject in your case. DataBinder.Eval dynamicaly looks up
    > on the first parameter the propery specified by the secon parameter and
    > returns the string representation. this is used to fill in the Repeter's
    > rendering.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >> Given databinding an array of System.Version types:
    >>
    >> Given that "SomeObject" type has a Version property:
    >>
    >> public class SomeObject
    >> {
    >> public Version Version { get; }
    >> public string Description { get; }
    >> }
    >> and I want to bind a list of them to a datagrid.
    >>
    >> DataGrid1.DataSource = someObjectList; // basically an array of
    >> "someobject" DataGrid1.DataBind();
    >>
    >> How does one utilize the DataBinder.Eval (and in asp.net v2.0, the
    >> Eval method) to get to the SomeObject.Version.Major property?
    >>
    >> (Assuming ALL that other stuff is Syntax proper, and so forth)
    >>

    >
    >
    >
     
    Eric Newton, Apr 4, 2005
    #3
  4. Eric Newton

    Brock Allen Guest


    > I was actually talking about the Version property's Major property...
    > because the following doesn't work:
    >
    > <%# DataBinder.Eval(Container.DataItem, "Version.Major") %>


    As long as those are all public properties (fields don't work), then that
    syntax should work fine.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, Apr 4, 2005
    #4
    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,275
    Lauchlan M
    Oct 15, 2003
  2. Tom Lee
    Replies:
    2
    Views:
    850
    Chris Carter
    Dec 9, 2003
  3. bg
    Replies:
    5
    Views:
    6,443
    Scott Allen
    Apr 16, 2004
  4. Ken Cox [Microsoft MVP]
    Replies:
    1
    Views:
    3,492
    Charlie@CBFC
    May 12, 2004
  5. Joe Rattz
    Replies:
    2
    Views:
    611
    Robert Koritnik
    Sep 10, 2004
Loading...

Share This Page