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();
        }
posted @ 2012-10-10 11:20  pantherbean  阅读(280)  评论(0编辑  收藏  举报