1

我只将图片名称存储在数据库中,实际图片存储在项目目录“SiteImages”中。

现在我想在 RDLC 报告中显示图像但不显示。代码:

public void Fill_AuditsReport()
{
    ReportViewer1.AsyncRendering = false;
    ReportViewer1.SizeToReportContent = true;
    ReportViewer1.ZoomMode = ZoomMode.FullPage;
    this.ReportViewer1.Reset();

    DataTable dt = new DataTable();
    PersonalInfo.ManagePersonalInfo MngPersonalInfo = new PersonalInfo.ManagePersonalInfo();

    dt = MngPersonalInfo.ReportSelectPersonalInfo();

    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/DataManagementReports/Report.rdlc");
    ReportDataSource rpds = new ReportDataSource("DataSetPersonalInfo", dt);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rpds);
    ReportViewer1.Visible = true;
}

数据库中字段的名称是PersonalInfoEmployeePicture

4

1 回答 1

4

将以下代码添加到您的项目中:

ReportViewer1.LocalReport.EnableExternalImages = true;
string FilePath = @"file:\" + Application.StartupPath + "\\" + "SiteImages\\"; //Application.StartupPath is for WinForms, you should try AppDomain.CurrentDomain.BaseDirectory  for .net
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("ImgPath", FilePath);
ReportViewer1.LocalReport.SetParameters(param);

然后在报表设计器中,确保 Image 项设置了图像源属性,External并且您有一个具有正确名称 (ImgPath) 的参数。然后简单地定义一个指向正确图像的表达式。(这取决于您在数据库中存储图像名称的方式,我们没有扩展名,我假设您添加了扩展名)

= Parameters!ImgPath.Value + Fields!PersonalInfoEmployeePicture.Value
于 2015-11-12T12:50:36.300 回答