Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从ImagePath检索图像_C#_Asp.net_Sql Server - Fatal编程技术网

C# 从ImagePath检索图像

C# 从ImagePath检索图像,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我在数据库中保存了一个图像路径,如下所示: C:\Users\3embed\Documents\Visual Studio 2010\Projects\HeritageWeb\HeritageWeb\Images\startbutton.png 我想将图像显示为缩略图。现在我正在使用以下代码: <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="7%" HeaderText="Icon">

我在数据库中保存了一个图像路径,如下所示:

C:\Users\3embed\Documents\Visual Studio 2010\Projects\HeritageWeb\HeritageWeb\Images\startbutton.png
我想将图像显示为缩略图。现在我正在使用以下代码:

<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="7%" HeaderText="Icon">
    <ItemTemplate>
        <asp:Image ID="ProfImage" ImageUrl='<%#Eval("Thumbnail","/Images/{0}")%>' runat="server" Width="30px" Height="30px"></asp:Image>
    </ItemTemplate>
</asp:TemplateField>


它给了我整条路。我只需要startbutton.png。但是,我需要将整个路径存储在数据库中,因为我需要将它存储在其他地方

有点乱,但请尝试替换以下内容

<%#Eval("Thumbnail","/Images/{0}")%>

使用(未经测试的和更新的


嘿!!谢谢我在进行更改时遇到以下错误:“System.Web.UI.IDataItemContainer.DataItem”不能像方法一样使用。@user1340516是否使用c#?如果是这样,请将
(“缩略图”)
更改为
[“缩略图”]
(很抱歉,您的问题中遗漏了c标记)是的,我正在使用c。。这就是错误现在已更改为的内容。。无法将带[]的索引应用于“object”Thankstorry类型的表达式,我通常不使用
Eval
,所以我会在黑暗中搜索一点。。。请尝试更新的答案谢谢您的回复。。但是现在我得到了这个错误:“System.IO.Path.GetFileName(string)”的最佳重载方法匹配有一些无效参数。真正的问题来自存储在DB中的数据。不要在数据库中存储指向文件物理存储位置的图像的完整路径。将应用程序部署到生产环境时会发生什么情况?到另一台服务器?路径:
C:\Users\3embed\Documents\visualstudio 2010\Projects\HeritageWeb\HeritageWeb\Images
在那里毫无意义。您应该只存储文件名,或web应用中图像的相对路径。谢谢。。到底是什么解决了我的问题:)