ASP.NET: Objects in Eval

If I have objects in my DataSource i.e.

.Select(e => new { Foo = new { Bar = "HelloWorld" }, Price = 12345 } 

How can I do this with Eval?

 <%# Eval("Foo.Bar") %> 

does not work? (Eval ("Price") does ....)

Do I need to do <% # Eval (Eval ("Foo"), "Bar")%> or something?

+4
source share
1 answer

If this applies to a DataBound control where you are binding to some list or anonymous IQueryable, you should be able to use Eval("Bar") since Foo is already specified in bind.

Edit:
If you want to use the notation <%# %> , look at your update, you can leave with it using Container.DataItem .

 <%# ((Foo)Container.DataItem)["Bar"] %> 
+6
source

All Articles