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

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)
 
B

Brock Allen

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.
 
E

Eric Newton

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
 
B

Brock Allen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top