2009-04-28 106 views
0

我正在使用ListView控件来显示图片以及说明和标题。我曾经在url字段中保存图像的完整路径,所以当我在ListView中显示它们时,我不需要编辑任何东西。现在我正在使用类似于:列表视图显示图片

HttpContext.Current.Server.MapPath("~/photos/") + savedURL 

如何编辑我的ListView以使其显示图像?

我使用时,GridView的RowDataBound事件我操作的内容等,以做同样的GridView控件:

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) 

回答

1

你为什么不只是使用Image控件在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> 
0

你试过

ResolveUrl("~/photos/") + savedURL; 
+0

试试吧在哪里?我没有编辑列表视图,我在问如何编辑它以使其与HttpContext.Current.Server.MapPath(“〜/ photos /”)+ savedURL或您建议的代码一起工作,我应该在哪里编辑? – Maen 2009-04-28 14:13:54

0

你有没有考虑使用一个中继器,只是设置中继器的模板显示完全符合您的需要?是否有任何特定原因希望在Repeater上使用ListView?