关于在报表中添加图片的内容,网上有很多。但一直没找到合适的,今天才发现一个方法给了我提示,现在把它写出来,希望能帮助和我一样聚到问题的朋 友: 在ReportViewer中添加RDLC就不细说了,这里说明我的情况,我在报表中要显示作品下载信息,其中包含的有作品的缩微图,图片物理文件存在 项目中,数据库中保存的为相对路径。在RDLC中的Table相应列添加一个Image,设定其Source属性为External,Value属性为数 据源相应字段(图片路径)值,我是用List《》集合添加的,value值得格式为:="file:///" & Fields!CUPDLR_ProSmallLogoPath.Value(CUPDLR_ProSmallLogoPath为数据库相应字段),这里的”file:///“是非常重要的,不能缺省。后面接的是图片的物理路径,在cs文件中我已改动 至此,RDLC已基本设定好。在cs文件中:
- protected void BindReportViewer(int year, int month) {
- int proCount = 0;
-
- List list = BComUserProDownLoadReport.GetList(year, month, comId,out proCount);
- UpdateImgURL(list);
-
- this.ReportViewer1.LocalReport.EnableExternalImages = true;
- ReportParameter param1 = new ReportParameter("CurrentDate", year.ToString() + "-" + month.ToString());
- ReportParameter param2 = new ReportParameter("CompanyName", "金长城");
- ReportParameter param3 = new ReportParameter("ProductCount", proCount.ToString());
- ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { param1, param2,param3 });
-
- ReportDataSource rds = new ReportDataSource("ComUserProDownLoadReportDataSet_DataTable1", list);
- this.ReportViewer1.LocalReport.DataSources.Clear(); this.ReportViewer1.LocalReport.DataSources.Add(rds);
- this.ReportViewer1.LocalReport.Refresh();
- }
-
- protected void UpdateImgURL(List list) {
- foreach (ADOnline.Model.ComUserProDownLoadReport cplr in list) {
- if (cplr.CUPDLR_ProSmallLogoPath != null && cplr.CUPDLR_ProSmallLogoPath.Trim().Length > 0)
- cplr.CUPDLR_ProSmallLogoPath = Server.MapPath(cplr.CUPDLR_ProSmallLogoPath);
- }
- }
显示外部图片的关键部分就是file:///+图片物理路径,其他的根据自己需求做相应的更改吧!时间关系,不再啰嗦了!