濮阳杆衣贸易有限公司

主頁 > 知識庫 > Asp.net 自帶報表的使用詳解

Asp.net 自帶報表的使用詳解

熱門標簽:怎么給超市做地圖標注入駐店 世紀佳緣地圖標注怎么去掉 十堰正規(guī)電銷機器人系統(tǒng) 巫師3為什么地圖標注的財寶沒有 外呼系統(tǒng)費用一年 手機地圖標注如何刪除 寧波自動外呼系統(tǒng)代理 外呼系統(tǒng)代理品牌 辦理400電話證件

1:新建報表所需的數(shù)據(jù)源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方法名稱隨便起,也可以在一個類裏面定義多個方法(不同數(shù)據(jù)源)

2:設計報表

報表設計這裡就不涉及了

3:把第一步新建的數(shù)據(jù)源加到報表裏面綁定

 注意:這裡需要先引用 Interop.VBA.dll 才可以把新建的CS文件作為數(shù)據(jù)源導入

 

把數(shù)據(jù)源導入后綁定即可

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為報表裏面的數(shù)據(jù)源名稱
            viewer.LocalReport.DataSources.Add(rds_1);

            ReportParameter rp1 = new ReportParameter("參數(shù)1","參數(shù)1的值" );//給參數(shù)賦值
            ReportParameter rp2 = new ReportParameter("參數(shù)2","參數(shù)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();//自己拼出數(shù)據(jù)源就可以
                ReportDataSource repDataSource = new ReportDataSource("DataSet1", dt);

                //*設置報表參數(shù),并顯示
                this.rpResut.LocalReport.ReportEmbeddedResource = "***.Page.Report.Report1.rdlc"";
                this.rpResut.LocalReport.DataSources.Clear();
                this.rpResut.LocalReport.DataSources.Add(repDataSource);
                 ReportParameter rp1 = new ReportParameter("參數(shù)1","參數(shù)1的值" );//給參數(shù)賦值
                  ReportParameter rp2 = new ReportParameter("參數(shù)2","參數(shù)2的值" );

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

至此,報表的產(chǎn)出和顯示都OK了,如果需要更深入的了解,請查看其它文章

標簽:山西 泰州 景德鎮(zhèn) 通遼 天門 嘉興 牡丹江

巨人網(wǎng)絡通訊聲明:本文標題《Asp.net 自帶報表的使用詳解》,本文關鍵詞  Asp.net,自帶,報表,的,使用,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關。
  • 相關文章
  • 下面列出與本文章《Asp.net 自帶報表的使用詳解》相關的同類信息!
  • 本頁收集關于Asp.net 自帶報表的使用詳解的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    吴江市| 香港| 德令哈市| 四川省| 海原县| 桐梓县| 项城市| 海阳市| 伽师县| 长丰县| 牙克石市| 平顺县| 确山县| 高平市| 宜都市| 友谊县| 鲁山县| 武清区| 克什克腾旗| 吉木乃县| 斗六市| 奉贤区| 玉环县| 凤城市| 通河县| 长治市| 任丘市| 开原市| 页游| 定日县| 红安县| 土默特右旗| 哈尔滨市| 乌兰察布市| 河北区| 邢台县| 宣恩县| 焦作市| 高尔夫| 怀柔区| 慈溪市|