最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2013年10月11日 15:22:00   作者:  
最近公司的功能需要使用報表,用的是微軟自帶的報表,談一談我們的做法,希望可以給想學(xué)習(xí)的人一些指導(dǎo)

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

2:設(shè)計報表

報表設(shè)計這裡就不涉及了

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

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

 

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

4:直接把報表導(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為報表裏面的數(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為報表控件)

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

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

                //*設(shè)置報表參數(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了,如果需要更深入的了解,請查看其它文章

相關(guān)文章

最新評論

青神县| 嘉善县| 女性| 连州市| 镇巴县| 连山| 宽城| 同心县| 荣昌县| 绿春县| 年辖:市辖区| 醴陵市| 武鸣县| 靖远县| 叶城县| 湘乡市| 淮安市| 保亭| 云龙县| 江口县| 鹤岗市| 甘德县| 铜鼓县| 岫岩| 长宁县| 赣榆县| 永川市| 张北县| 蒙山县| 长乐市| 四子王旗| 延川县| 泌阳县| 正定县| 防城港市| 彭泽县| 班玛县| 深泽县| 三门县| 保山市| 平泉县|