views:

176

answers:

3

Here's how I pull a field from my object: <%# DataBinder.Eval(Container.DataItem, "Name") %>

However, how do I pull a field if it's in a subclass (Customer.ContactInfo.Name)?

+6  A: 

If you know that the DataItem is a certain type (let's say you know it's a CustomerInfo type), you can do this:

<%# ((CustomerInfo) Container.DataItem).ContactInfo.Name %>

As a bonus, it's somewhat quicker than using DataBinder.Eval, because you avoid all the overhead of reflection.

Keltex
+3  A: 

Try...

<%#((Customer)Container.DataItem).ContactInfo.Name%>
fung
Got beaten to it again. And with better whitespacing, too. =)
fung
@fung Sorry... I gave you an upvote anyway...
Keltex
@Keltex Likewise. +1 on the Eval. People should really stop using it even for a single level bind.
fung
+1  A: 

If the repeater is being bound to a collection of Customer objects then to grab the name from the contact info: <%# DataBinder.Eval(Container.DataItem, "ContactInfo.Name") %>

mccrager