首页 > 解决方案 > 当路径在 RDLC 报告中的数据库中时显示文件夹中的图像

问题描述

如何显示位于文件夹中且路径在数据库中的学生图片但我无法做到我搜索了很多但没有发现任何有用的东西。请帮帮我

在此处输入图像描述 我越来越像这样

            protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                string query = @"select StudentID,c.DocumentType as DocumentID,DocumentNumber,Name,NameDari,FatherName,FatherNameDari,MobileNumber,Photo,b.ClassName as ClassID,d.LocationName as LocationID,e.TeacherName as TeacherID,a.Term,a.Score from StudentsInfo a 
join Class b 
on a.ClassID=b.ClassID
join Document c
on c.DocumentID=a.DocumentID
join Location d
on d.LocationID=a.LocationID
join Teachers e
on e.TeacherID=a.TeacherID";
                var data = db.Database.SqlQuery<StudentsInfo>(query);
                ReportViewer1.SizeToReportContent = true;
                ReportViewer1.LocalReport.ReportPath = Server.MapPath("Certificates.rdlc");

                ReportViewer1.LocalReport.DataSources.Clear();
                ReportDataSource ds = new ReportDataSource("Certificates", data);
                ReportViewer1.LocalReport.DataSources.Add(ds);
                this.ReportViewer1.LocalReport.EnableExternalImages = true;
                ReportViewer1.LocalReport.Refresh();
            }

        }

标签: asp.net-mvcrdlc

解决方案


首先,确保您已经在 RDLC 报表设计器中完成了这些步骤:

1)从图像源属性设置“外部”模式。

2)Add Parameter使用上下文菜单创建一个报告参数以保存从代码后面插入的路径。

然后,您可以在启用后尝试以下示例EnableExternalImages

this.ReportViewer1.LocalReport.EnableExternalImages = true;

/* begin added part */

// get absolute path to Project folder
string path = new Uri(Server.MapPath("~/path/to/Project/folder")).AbsoluteUri; // adjust path to Project folder here

// set above path to report parameter
var parameter = new ReportParameter[1];
parameter[0] = new ReportParameter("ImagePath", path); // adjust parameter name here
ReportViewer1.LocalReport.SetParameters(parameter);
/* end of added part */

ReportViewer1.LocalReport.Refresh();

然后在报表表达式编辑器中,定义连接插入路径ReportParameter和存储路径的简单表达式(此处参数名称应与ReportParameter上面的示例代码匹配):

=Parameters!ImagePath.Value + Fields!Photo.Value

参考:


推荐阅读