rdlc 报表步骤

1.在类中创建一个返回值是List<T>的方法,注意:返回值必须是List<T>,不能是其它类型,如string,int,否则当报表新建数据集的时候,是找不到数据源的.

2.新建报表Report1.rdlc

3.新建数据集

4.插入表

5 在表填入数据集中的字段

6

 protected void Page_Load(object sender, EventArgs e)
        {
            LocalReport report = new LocalReport(); //新建报表对象
            report.ReportPath = Server.MapPath("/report1.rdlc");//报表路径
            ReportDataSource dataSource = new ReportDataSource("DataSet1", new users().GetUserList());//报表的数据源,此处DataSet1是刚才建的数据集DataSet1
            report.DataSources.Add(dataSource);//把数据源加载到报表对象中
            string reportType = "pdf";//还可以是,word,excel
            string mimeType;
            string encoding;
            string fileNameExtension;
            string deviceInfo = "";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;
            renderedBytes = report.Render(//将报表转化为字节
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode("myreport.pdf", System.Text.Encoding.UTF8));//格式还可以是:docx,xls
            Response.BinaryWrite(renderedBytes);
            Response.Flush();
            Response.End();
        }

转载于:https://www.cnblogs.com/panthervic/archive/2012/10/10/2718004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值