【发布时间】:2015-12-08 17:43:10
【问题描述】:
为什么在 Gridview 中没有加载图像?
<asp:GridView runat="server" ID="grdviewPropertyDetails" OnRowCommand="grdviewPropertyDetails_RowCommand" DataKeyNames="pk_PropertyDetails_PropertyDetailsID" AutoGenerateColumns="false" CssClass="table table-condensed table-bordered table-striped table-responsive">
<Columns>
<asp:ImageField DataImageUrlField="PropertyDetailsFardPath" HeaderText="Fard Path" ControlStyle-Width="100" ControlStyle-Height = "100" />
<asp:ButtonField CommandName="cmdEdit" ImageUrl="~/assets/global/images/shopping/edit.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="25px" />
<asp:ButtonField CommandName="cmdDelete" ImageUrl="~/assets/global/images/shopping/delete.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="25px" />
</Columns>
</asp:GridView>
返回的路径是这样的
G:\Study & Official Projects\Office Projects\Municipal Corporation\MCP-Building Plan Approval\MCP-Building Plan Approval\SiteImages\fard 2.png
是的,图像在其中,但 gridview 列是空的。
P.S 我像这样将它保存到数据库中:
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/SiteImages/") + fileName);
HdnFieldFard.Value = Server.MapPath(FileUpload1.FileName);
ResultLabel.ResultLabelAttributes("Image Uploaded", ProjectUserControls.Enums.ResultLabel_Color.Red);
ResultPanel.Controls.Add(ResultLabel);
}
和
string FardImagePath = HdnFieldFard.Value;
然后通过发送 FardImagePath 插入到数据库中
【问题讨论】:
-
因为你只在数据库中存储文件名,所以如何在没有路径的情况下显示图像? HdnFieldFard 只包含文件名而不是完整路径。
-
如何获取完整路径?
-
你可以在db中存储fullpath + imagename。
-
我将其存储在 DATABASE G:\Study & Official Projects\Office Projects\Municipal Corporation\MCP-Building Plan Approval\MCP-Building Plan Approval\SiteImages\fard 2.png
-
如何在路径中添加“SiteImages”文件夹?
标签: c# asp.net visual-studio gridview webforms