Today I received an email regarding one of my
previous posts:
re: ObjectDataSource, GridView, and DataKeyNames
Now, if my Person class has a property Country which returns a Country
object (with properties CountryId and CountryName). How would you bind a
gridview to display the list of persons (with Id, Name, Age and CountryName).
The only way I could get this to work is to have the CountryName as a
property on the Person class, which becomes unacceptable for more complex
classes. Any ideas?
The answer is: create a template field and use Eval(). I have been able to
bind to a graph of objects like this without any problems.
<asp:TemplateField
HeaderText="CountryName">
<ItemTemplate>
<%#
Eval("Country.CountryName")
%>
</ItemTemplate>
</asp:TemplateField>
Hope that helps.