为什么在网格视图中图片没有显示?

3
<asp:TemplateField HeaderText="Image">
    <ItemTemplate>
        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("imagepath") %>' Height="100px"
                   Width="100px" />
    </ItemTemplate>
</asp:TemplateField>

绑定的路径是来自一个表格:C:/inetpub/wwwroot/Image/FolderName/abc.jpg,但图片无法显示。图片与该文件夹同级且未出现任何异常。

你不能像那样给出图片路径,必须将其更改为 ~/Image/FolderName/abc.jpg - Sandeep
但是这张图片不在我的应用程序文件夹中,它在外面。 - Pwavel002
请查看此链接:http://www.codeproject.com/Articles/20782/Displaying-Images-from-a-Database-in-a-GridView - Mairaj Ahmad
你能否将数据库中 imagepath 列的原始路径发送给我们?我的意思是它来自哪里? - Keval Gangani
2
@Pwavel002,你将无法使用该路径显示图像。你必须将其添加到应用程序文件夹中,或者可以创建httphandler或使用此文章 - Sandeep
显示剩余4条评论
3个回答

2
<img src='<%# Eval("imagepath").ToString() %>' Width="100px" Height="100">

也许你可以做类似的事情吗?

0

这些代码是GridView的数据源

<asp:GridView ID="grv" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1">
             <Columns>
                <asp:BoundField DataField="PicID" HeaderText="PicID" ReadOnly="True" InsertVisible="False" SortExpression="PicID"></asp:BoundField>
                <asp:BoundField DataField="PicURL" HeaderText="PicURL" SortExpression="PicURL"></asp:BoundField>
                <asp:BoundField DataField="PicName" HeaderText="PicName" SortExpression="PicName"></asp:BoundField>
                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date"></asp:BoundField>
            </Columns>
            <Columns>
                <asp:BoundField HeaderText="Picutre ID" DataField="PicID"></asp:BoundField>
                <asp:BoundField HeaderText="Title" DataField="PicName"></asp:BoundField>
                <asp:BoundField HeaderText="Date Added" DataField="Date" DataFormatString="{0:d}"></asp:BoundField>
                <asp:ImageField DataImageUrlField="PicURL" ></asp:ImageField>
            </Columns>
        </asp:GridView>

这些代码是SQL表格

CREATE TABLE PicTable
(
PicID int identity(1,1),
PicURL nvarchar(50),
PicName nvarchar(50),
Date datetime
);


select * from PicTable
insert PicTable values('~/Uploads/4626411630_ASO%20(1).jpg','Water Lilies','2015.02.27')

你可以像这样添加值。 你必须在解决方案资源管理器中有一个文件夹。 例如,我的文件夹名称是Uploads。 我希望这些代码对你或其他开发人员有所帮助。


0
Instead you can directly convert the BLOB or Binary in <asp:Image> tag and click on the Button Tag, it will take you to the IndexChangedFunction and you can do further operations with the grid:

    <asp:GridView ID="Gvid" runat="server" Width="100%" AutoGenerateColumns="false" OnSelectedIndexChanged="Gvid_SelectedIndexChanged" >
            <Columns>
<asp:TemplateField HeaderText="IMAGE" Visible="false">
<ItemTemplate>
<asp:Image runat ="server"  ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("IMAGE")) %>' ID="Image"  />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField DataTextField ="MODEL" CommandName="select" HeaderText ="MODEL" />
</Columns> 
</asp:GridView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接