在RDLC报表中动态加载图片

原文
场景:从数据读取数据集,在RDLC报表控件中展现。其中一字段保存的是图片的虚拟路径,图片源文件保存在服务器的固定文件夹中。

重点:在RDLC中显示图片必须满足两个条件,才能执行正常。处理方式略过,
1、图片完整的绝对路径。
2、完整绝对路径前必须加上 “file:\”; 例如:file:\G:\Project\Upload\Images\aaa.jpg
建议:直接在SQL语句中拼接完整绝对路径。

RDLC图片控件属性设置:

1、在报表适合的位置中放Image控件,并按照下图设置。选择“外部”,并选择数据库字段。
在这里插入图片描述

2、代码中设置属性。

 this.ReportViewer1.LocalReport.EnableExternalImages = true;

完整代码:

        DataTable dtSource = new AttendanceBLL().GetUserAttendanceListByYearMonth(GetParameter());
        this.ReportViewer1.Visible = false;
        lblText.Visible = false;
        if (dtSource.Rows.Count > 0)
        {
            string reportPath = "";
            string reportSource = "";
            reportPath = "Reports/UsersAttendance.rdlc";
            reportSource = "Attendance";
            this.ReportViewer1.LocalReport.DataSources.Clear();
            lblText.Visible = false;
            this.ReportViewer1.LocalReport.ReportPath = reportPath;
            this.ReportViewer1.LocalReport.EnableExternalImages = true;
            ReportDataSource rds = new ReportDataSource(reportSource, dtSource);
            this.ReportViewer1.LocalReport.DataSources.Add(rds);
            this.ReportViewer1.LocalReport.Refresh();
            this.ReportViewer1.Visible = true;
        }
        else
        {
            this.ReportViewer1.Visible = false;
            lblText.Visible = true;
        }

效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值