views:

598

answers:

3

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)
A: 

Have you tried

ResolveUrl("~/photos/") + savedURL;
Eoin Campbell
Try it where? I did not edit the list view, I am asking how to edit it to make it work with HttpContext.Current.Server.MapPath("~/photos/") + savedURL or the code you suggested, where should I edit?
Maen
Can you post the code for your listview (or whatever your currently doing) so we can see where you're going wrong
Eoin Campbell
A: 

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?

Kelsey
+1  A: 

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>
Canavar