欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

Asp.net 自带报表的使用详解

时间:2021-03-02 11:44:33|栏目:.NET代码|点击:

1:新建?蟊硭?需的???源DataSet.cs

复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace ********
{
    public class DataSet
    {
        public DataTable CreatDataSet()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("A");
            dt.Columns.Add("B");
            dt.Columns.Add("C");
            return dt;

        }
    }
}


指定所需要?定的Table的列,返回dataTable ?,CreatDataSet方法名?Q?S便起,也可以在一????Y面定?x多??方法(不同???源)

2:?O??蟊?

?蟊碓O??@?e就不涉及了

3:把第一步新建的???源加到?蟊硌Y面?定

 注意:?@?e需要先引用 Interop.VBA.dll 才可以把新建的CS文件作????源??入

 

把???源??入后?定即可

4:直接把?蟊?С??PDF,Excel等格式

复制代码 代码如下:

ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportEmbeddedResource = "***.Page.Report.Report1.rdlc";
            ReportDataSource rds_1 = new ReportDataSource("DataSet1", dtReport);//DataSet1??蟊硌Y面的???源名?Q
            viewer.LocalReport.DataSources.Add(rds_1);

            ReportParameter rp1 = new ReportParameter("???1","???1的值" );//?o??蒂x值
            ReportParameter rp2 = new ReportParameter("???2","???2的值" );
            viewer.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });

            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;

            byte[] bytes = viewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
            //Excel ,PDF ,Word 等格式
            // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment; filename=1_" + DateTime.Now.ToString("yyyyMMddhhssmm") + "" + "." + extension);
            Response.BinaryWrite(bytes); // create the file
            Response.Flush(); // send it to the client to download

5:在?面引用?蟊恚?rpResult??蟊砜丶?)

复制代码 代码如下:

DataTable dt = new DataTable();//自己拼出???源就可以
                ReportDataSource repDataSource = new ReportDataSource("DataSet1", dt);

                //*?O置?蟊???,并?@示
                this.rpResut.LocalReport.ReportEmbeddedResource = "***.Page.Report.Report1.rdlc"";
                this.rpResut.LocalReport.DataSources.Clear();
                this.rpResut.LocalReport.DataSources.Add(repDataSource);
                 ReportParameter rp1 = new ReportParameter("???1","???1的值" );//?o??蒂x值
                  ReportParameter rp2 = new ReportParameter("???2","???2的值" );

                this.rpResut.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });
                this.rpResut.DataBind();
                this.rpResut.LocalReport.Refresh();

至此,?蟊淼漠a出和?@示都OK了,如果需要更深入的了解,?查看其它文章

上一篇:ASP.NET中Form表单不可以嵌套使用

栏    目:.NET代码

下一篇:使用UserControl做网站导航条的思路 分析

本文标题:Asp.net 自带报表的使用详解

本文地址:http://www.codeinn.net/misctech/72539.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有