佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > Asp.net 自帶報(bào)表的使用詳解

Asp.net 自帶報(bào)表的使用詳解

熱門標(biāo)簽:國(guó)美全國(guó)運(yùn)營(yíng)中心 百度AI接口 電銷業(yè)務(wù) 客戶服務(wù) 電商新玩法 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 人工智能 網(wǎng)站排名優(yōu)化

1:新建報(bào)表所需的數(shù)據(jù)源DataSet.cs

復(fù)制代碼 代碼如下:

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方法名稱隨便起,也可以在一個(gè)類裏面定義多個(gè)方法(不同數(shù)據(jù)源)

2:設(shè)計(jì)報(bào)表

報(bào)表設(shè)計(jì)這裡就不涉及了

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

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

 

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

4:直接把報(bào)表導(dǎo)出為PDF,Excel等格式

復(fù)制代碼 代碼如下:

ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportEmbeddedResource = "***.Page.Report.Report1.rdlc";
            ReportDataSource rds_1 = new ReportDataSource("DataSet1", dtReport);//DataSet1為報(bào)表裏面的數(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:在頁(yè)面引用報(bào)表(rpResult為報(bào)表控件)

復(fù)制代碼 代碼如下:

DataTable dt = new DataTable();//自己拼出數(shù)據(jù)源就可以
                ReportDataSource repDataSource = new ReportDataSource("DataSet1", dt);

                //*設(shè)置報(bào)表參數(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();

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

標(biāo)簽:南平 廈門 棗莊 POS機(jī) 咸寧 拉薩 益陽(yáng) 攀枝花

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Asp.net 自帶報(bào)表的使用詳解》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    龙里县| 江源县| 思南县| 明星| 洞头县| 顺平县| 孟连| 双流县| 陆河县| 贡山| 疏勒县| 永安市| 黎城县| 昆山市| 贡觉县| 广德县| 石河子市| 晋州市| 原平市| 北宁市| 澳门| 马关县| 江永县| 盐源县| 普兰县| 武胜县| 同仁县| 四川省| 冕宁县| 贵阳市| 郑州市| 万年县| 康保县| 黎平县| 罗定市| 福建省| 南溪县| 永年县| 兖州市| 玉林市| 尚义县|