I am using a listview to display a list of all the users of my site. A user can upload multiple images, so when i generated my model with entity framework, 2 entities were created: Users and Images. User had a navigation property to a collection of images and Images had a navigation property to a single user.
I am now trying to display in my listview 1 of the images uploaded by the user (if he has uploaded any).It doesn’t matter which one is being displayed.
I created an EntityDataSource, and i’ve added “Images” into it’s include property. Then, i branched my listview to the datasource. usually, to display the content of the navigation property, i use something like
<asp:Label ID="fn" runat="server" Text='<%# Eval("Users.Firstname") %>' />
However, since it’s column of a collection that i’m trying to display,can i use something like this? IF so, what would be a propper way to manage the case where the user didn’t upload any image?
<asp:image ID="img" runat="server" ImageUrl='<%# Eval("Images[0].path") %>' AlternateText="" />
Evalis using reflection and it has its limitations on more complicated terms. You should not be afraid of direct casting:Note that in order to cast to
YourObjectTypeyou will probably have to add an<@Import >directive to the page (or alternatively use a full type name, including the namespace).