How's that for a title? I am trying to get a the maxinum number of hits for the keywords I'd use on Google for this one since it wasn't all that straightforward.
Let's say you are using the object datasource to return a generic list of address objects. Inside the address object is a "subobject" called address type which has properties of description and id.
The question is, since the gridview's list of available columns doesn't drill into the subobject, how do I display the description property on AddressType?
The answer lies within the template column. <minirant>Template columns are a favorite of mine from the old datagrid days in that they allow you to do pretty much whatever your heart desires. The problem is the usage of them is rather poorly documented so you usually have to go to blogs and newsgroups to find information like this.</minirant> Anyways, here's the solution:
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="lblAddressType" runat="server" Text='<%# ((Address)(Container.DataItem)).AddressType.Description %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
As you can see I'm casting the dataitem as the parent object (Address) and then just calling the property like you would in a codebehind!