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

  • Thread starter Thread starter Eric Newton
  • Start date Start date
E

Eric Newton

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)
 
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
 
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
 
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
 
Back
Top