Reputation: 1030
I am using a ListView control to display Pictures along with description and caption. I used to save the full path of the image in the url field, so when I display them in the ListView I don't need to edit anything. Now I am using something like:
HttpContext.Current.Server.MapPath("~/photos/") + savedURL
How can I edit my ListView to make it show the images?
I used to do the same to GridView when in GridViews RowDataBound event I manipulate the contents like:
Dim photo As New Image
photo.ImageUrl = "~/photos/" + e.Row.Cells(TheCellNumber).Text
e.Row.Cells(0).Controls.Clear()
e.Row.Cells(0).Controls.Add(photo)
Upvotes: 0
Views: 10324
Reputation: 48088
Why don't you just use Image control in ItemTemplate :
<asp:ListView ID="ListView1" runat="server" DataKeyNames="pictureId">
<ItemTemplate>
<asp:Image
id="pictureControlID" runat="server" AlternateText='<% #Eval("pictureName") %>'
ImageUrl='<%# "~/photos/" + Eval("picturePath") %>' />
</ItemTemplate>
</asp:ListView>
Upvotes: 1
Reputation: 47726
Have you considered using a Repeater and just setting the repeater's template to display exactly like you need? Was there any specific reason you wanted to use a ListView over a Repeater?
Upvotes: 0