rdlc实现动态插入图片

1、建一个rdcl 放入一个Tablix控件,删除Tablix的头和尾部,只保留detial,

2、放一个Textbox到detial中。并设置报表数据源 (该数据源中包含图片路径的字段)

3、设置Tablix的 datasetName (该数据源中包含 图片的路径)

4、设置Textbox的背景表达式 (文件框-》属性-》填充-》表达式 =Fields!path.Value)

5、加载数据源代码与加载报表

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Reporting.WinForms;

namespace Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string ff = @"d:\\年会抽奖券图片";
        private void Form1_Load(object sender, EventArgs e)
        { 
            //显示本地图片的属性打开
            this.reportViewer1.LocalReport.EnableExternalImages = true;
            
            List<PicPath> list1 = new List<PicPath>();
            List<PicPath> list2 = new List<PicPath>();
            string[] pics = Directory.GetFiles(@"d:\\年会抽奖券图片", "*.jpg");
        //  for (int i = 0; i < pics.Length; i++)
            //   for (int i = 0; i <400; i++)
              for (int i =53; i < 55; i++)
            {

               //PicPath p = new PicPath();
               //p.path = @"file:///" + pics[i];
               //list1.Add(p);
               if (i % 2 == 0)
               {
                   PicPath p = new PicPath();
                   p.path = @"file:///" + pics[i];
                   list1.Add(p);
               }
               else
               {
                   PicPath p = new PicPath();
                   p.path = @"file:///" + pics[i];
                   list2.Add(p);
               }
           }

            
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", list1));
            this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", list2));
            using (MemoryStream ms = 
                new MemoryStream(Demo.Properties.Resources.Report1)
                        )
            {
                this.reportViewer1.LocalReport.LoadReportDefinition(ms);
            }
            this.reportViewer1.RefreshReport();
        }

         
    }
}

 

posted @ 2016-03-22 16:56  攻城狮caitou  阅读(2437)  评论(0编辑  收藏  举报