您的位置:首页 > 其它

[转帖]在RDLC中使用外部图片

2015-03-10 16:17 274 查看

原文链接:http://blog.csdn.net/rock870210/article/details/4559962

在RDLC中使用外部图片

2009-09-16 19:08 3416人阅读 评论(5) 收藏 举报
list报表数据库fileimagetable

关于在报表中添加图片的内容,网上有很多。但一直没找到合适的,今天才发现一个方法给了我提示,现在把它写出来,希望能帮助和我一样聚到问题的朋 友: 在ReportViewer中添加RDLC就不细说了,这里说明我的情况,我在报表中要显示作品下载信息,其中包含的有作品的缩微图,图片物理文件存在 项目中,数据库中保存的为相对路径。在RDLC中的Table相应列添加一个Image,设定其Source属性为External,Value属性为数 据源相应字段(图片路径)值,我是用List《》集合添加的,value值得格式为:="file:///" & Fields!CUPDLR_ProSmallLogoPath.Value(CUPDLR_ProSmallLogoPath为数据库相应字段),这里的”file:///“是非常重要的,不能缺省。后面接的是图片的物理路径,在cs文件中我已改动 至此,RDLC已基本设定好。在cs文件中:

[c-sharp] view plaincopy

protected void BindReportViewer(int year, int month) {

int proCount = 0;//记录作品数目

//获取list集合

List list = BComUserProDownLoadReport.GetList(year, month, comId,out proCount);

UpdateImgURL(list);//修改图片相对路径为物理路径

//this.ReportViewer1.LocalReport.EnableHyperlinks = true;

this.ReportViewer1.LocalReport.EnableExternalImages = true;//设定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:///+图片物理路径,其他的根据自己需求做相应的更改吧!时间关系,不再啰嗦了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: