HI
Im trying to show an image in a gridview, its held on the filesystem and the filename is returned in the datasource query.
If the fi开发者_开发技巧les are held in C:\TEMP, how would I properly structure the code below?
thanks
<asp:Image ID="Image" runat="server" ImageUrl='<%#"C:\TEMP\" + Eval("ImagePath") %>'
I believe it is along these lines
<asp:Image ID="Image" runat="server" ImageUrl="C:\TEMP\<%= Eval("ImagePath") %>"/>
In this scenario, your ImageUrl
value needs to be relative to the root of your web application so if your webapp is in:
c:\iis\MyWebApp
and images are in:
c:\iis\MyWebApp\img
the ImageUrl should evaluate to something like ~/img/Img1.jpg
You could store the full path e.g. `~/img/Image1.jpg' in the db or just the filename, in which case you need to add the path to the ImageUrl value either in code-behind or in the markup.
See this article for more information.
Hth.
精彩评论