4

If I have objects in my DataSource i.e

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

how do I reference this using Eval?

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

doesn't work? (Eval("Price") does....)

Is there anyway to do <%# Eval(Eval("Foo"),"Bar") %> or something ?

1 Answer 1

6

If this is in reference to a DataBound control where you're binding to some List or anonymous IQueryable, you should be able to use Eval("Bar") since the Foo is already indicated in the bind.

Edit:
Looking at your update, if you want to use the <%# %> notation, you might be able to get away with it by using Container.DataItem.

<%#  ((Foo)Container.DataItem)["Bar"] %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.