【发布时间】:2020-08-11 23:05:12
【问题描述】:
谁能指导我如何在 asp.net 的 gridview 上显示图像? 我从数据库中获取了图像路径,例如:D:\Picture\photo.jpg
我试过这个,但它在图像框中什么也没有。 我的前端代码:
<Columns>
<asp:BoundColumn DataField="id" HeaderText="Email ID" Visible="False">
<HeaderStyle />
</asp:BoundColumn>
<asp:BoundColumn DataField="photo_url" HeaderText="Photo" Visible="false">
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image ID="Image1" Height = "100" Width = "100" runat="server" DataImageUrlField = '<%# Eval("photo_url") %>' /> >>>>>>>>display image on this part
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="post_body" HeaderText="Post"></asp:BoundColumn>
<asp:BoundColumn DataField="post_id" HeaderText="Comment/Post ID" Visible="False">
<HeaderStyle Width="50px" />
</asp:BoundColumn>
</Columns>
【问题讨论】:
-
您遇到错误了吗?生成的 HTML 中是否出现了正确的 URL?
-
它没有出现任何错误,但是当运行它时,图像没有出现在图像列中,只是一个空列。从数据库获取 photo_url 的路径是正确的。它是 D:\Projects\Orlig_FB_Service\Images\wall_post_551183598322481_10152973356489762.jpg
-
是的,我知道,您在问题中说过。正确的 URL 是否出现在生成的 HTML 中?如果您手动导航到该 URL,图像会出现吗?
标签: asp.net gridview datagridview