asp.net-mvc - 当路径在 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();
}
}
解决方案
首先,确保您已经在 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
参考:
推荐阅读
- python - Python 获取 URL,打开输出文件,写入输出,关闭输出文件,结束 for 循环
- .net - Visual Studio 无法识别 Mac 上的项目
- javascript - 使用不同类型的 Javascript 标签在 HTML 文档中实现全局变量
- php - 当我需要传递自定义选项时如何使用 PHP curl_multi_init() 用法?
- android - 如何在颤动中绘制自定义动态高度曲线形状?
- arrays - Swift数组中texview中的所有字符
- javascript - 如果我有多个具有相同选项的选择标签,如何将警报按钮添加到单选选项?
- python - 如何在pygame中将矩形对象限制在给定坐标的边缘?
- python - python转换列的日期时间格式
- reactjs - 元素停止移动后如何将焦点设置为输入?