I have a ListView, which is bound with a list of 'A', which looks like this:
Class A
Property Id as Integer
Property TestStringA as String
Property B as B
End Class
Class B
Property Id as Integer
Property TestStringB as String
End Class
In the ListView i can refer to 'link property' values (whats the correct term for this?):
<asp:ListView runat="server" ID="lwTest" ItemType="A">
<LayoutTemplate>
<tr runat="server" id="itemPlaceHolder"></tr>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Item.TestStringA %></td>
<td><%# Item.B.TestStringB %></td> (this is what I mean)
</tr>
</ItemTemplate>
</asp:ListView>
This is also working when using the Eval-method (if unable to use 'ItemType'):
<%# Eval(B.TestStringB) %>
I want to loop the ListView´s items and use the values from the container, without saving them in hidden fields (isn't that the purpose of 'DataKeyNames'?). The issue is, that I can not refer to a property of another object by it's link-attribute/property (in the example B.Id) in DataKeyNames. When I do like this, I get an error telling me that there´s no property called 'B.Id'):
<asp:ListView runat="server" ID="lwTest" ItemType="A" DataKeyNames"Id, B.Id">
<LayoutTemplate>
<tr runat="server" id="itemPlaceHolder"></tr>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Item.TestStringA %></td>
<td><%# Item.B.TestStringB %></td> (this is what I mean)
</tr>
</ItemTemplate>
</asp:ListView>
Does anyone know if it is possible to do this? I know that I can add readonly properties returning the value directly to the bound object (but I would like to avoid this if possible):
Class A
Property Id as Integer
Property TestStringA as String
Property B as B
ReadOnly Property BId as Integer
Get
Return B.Id
End Get
End Property
End Class
Class B
Property Id as Integer
Property TestStringB as String
End Class
Thank you in advance!