您好,我想显示位于文件夹中且路径位于数据库中的学生照片,但是我无法做到这一点,但我搜索了很多,但发现没有任何用处。 请帮帮我
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();
}
}
答案 0 :(得分:2)
首先,请确保您已在RDLC报表设计器中完成以下步骤:
1)从图像源属性设置“外部”模式。
2)创建一个报告参数,以使用上下文菜单中的karma.conf.js
保留代码后面的插入路径。
然后,您可以在启用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
参考文献: