这是我从对象中提取字段的方法:
但是,如果字段位于子类 (Customer.ContactInfo.Name) 中,我该如何提取?
如果您知道 DataItem 是某种类型(假设您知道它是 CustomerInfo 类型),您可以这样做:
<%# ((CustomerInfo) Container.DataItem).ContactInfo.Name %>
作为奖励,它比使用 DataBinder.Eval 快一些,因为您避免了反射的所有开销。
尝试...
<%#((Customer)Container.DataItem).ContactInfo.Name%>
如果转发器被绑定到客户对象的集合,则从联系信息中获取名称: