RDLC報表,純文字內容,動態資料源 解決方案

來源:互聯網
上載者:User

本文轉自:http://www.cnblogs.com/jeekun/archive/2011/01/16/1936530.html

最近在做一個教育相關的項目,遇到很多的報表,在一位學長的推薦下使用了RDLC。

這個系統基本上都是簡單的查詢資料,沒有別的複雜的功能,下簡單記錄下個人使用心得,以便以後使用。

如果能幫到需要瞭解RDLC的人更是非常開心。

 

系統是 三層架構 + 預存程序 開發

資料庫連接字串在Web.Config儲存,經常會改變。

網上很多的RDLC教程都是說資料來源都是說添加資料來源,然後拖過來一個表什麼的,但是這對於實際項目顯然不缺實際,因此需要改變思路。

 

我的方法是:手動添加一個 資料集 Dataset

然後,右擊add->column 添加預存程序或者其他資料來源所查詢到的所有的資料列。

然後添加RDLC報表檔案,功能表列選擇 報表->資料來源

選中建立的DATASET,然後添加到報表。

一般顯示資料都是用表格,故拖出一個表格,在第二行,詳細資料裡右擊選擇運算式。

彈出如下對話方塊。

 

可選內容很多。因為我們制定的是資料集,選擇欄位就可以看到。然後雙擊就得到運算式。

當然也可以選擇其他,比如參數。可以在報表介面 選擇 報表- 報表參數,添加參數。

這裡報表就配置好了。

剩下的就是顯示了。需要一個asp.net空間 ReportViewer.

在適當的時候為它賦資料來源。

代碼如下:

 

private CommonLogic mCommonLogic = null;        private SqlParameter[] mSqlParameters = null;        private Microsoft.Reporting.WebForms.ReportParameter[] mReportParams = null;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                if (Request.QueryString["ReportPath"] != null)                {                    ViewState["ReportPath"] = Request.QueryString["ReportPath"];                    mCommonLogic = new CommonLogic("Report" + ViewState["ReportPath"]);                }                mSqlParameters = (SqlParameter[])Session["Parameters"];                for (int i = 0; i < mSqlParameters.Length; i++)                {                    if (mSqlParameters[i].Value != null && mSqlParameters[i].Value.ToString() == "---請選擇---")                    {                        mSqlParameters[i].Value = DBNull.Value;                    }                }                DataTable aTable = mCommonLogic.ExecFun((SqlParameter[])Session["Parameters"]);                ReportViewer1.Reset();                ReportViewer1.LocalReport.ReportPath = MapPath("~/tab/report/" + ViewState["ReportPath"].ToString() + ".rdlc");                ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource(ViewState["ReportPath"] + "_" + ViewState["ReportPath"], aTable));                if (Session["ReportParams"] != null)                {                    mReportParams = (Microsoft.Reporting.WebForms.ReportParameter[])Session["ReportParams"];                    ReportViewer1.LocalReport.SetParameters(mReportParams);                }                ReportViewer1.LocalReport.Refresh();                Session.Remove("Parameters");                Session.Remove("ReportParams");            }        }

 

 

 

 

 

 

最近在做一個教育相關的項目,遇到很多的報表,在一位學長的推薦下使用了RDLC。

這個系統基本上都是簡單的查詢資料,沒有別的複雜的功能,下簡單記錄下個人使用心得,以便以後使用。

如果能幫到需要瞭解RDLC的人更是非常開心。

 

系統是 三層架構 + 預存程序 開發

資料庫連接字串在Web.Config儲存,經常會改變。

網上很多的RDLC教程都是說資料來源都是說添加資料來源,然後拖過來一個表什麼的,但是這對於實際項目顯然不缺實際,因此需要改變思路。

 

我的方法是:手動添加一個 資料集 Dataset

然後,右擊add->column 添加預存程序或者其他資料來源所查詢到的所有的資料列。

然後添加RDLC報表檔案,功能表列選擇 報表->資料來源

選中建立的DATASET,然後添加到報表。

一般顯示資料都是用表格,故拖出一個表格,在第二行,詳細資料裡右擊選擇運算式。

彈出如下對話方塊。

 

可選內容很多。因為我們制定的是資料集,選擇欄位就可以看到。然後雙擊就得到運算式。

當然也可以選擇其他,比如參數。可以在報表介面 選擇 報表- 報表參數,添加參數。

這裡報表就配置好了。

剩下的就是顯示了。需要一個asp.net空間 ReportViewer.

在適當的時候為它賦資料來源。

代碼如下:

 

private CommonLogic mCommonLogic = null;        private SqlParameter[] mSqlParameters = null;        private Microsoft.Reporting.WebForms.ReportParameter[] mReportParams = null;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                if (Request.QueryString["ReportPath"] != null)                {                    ViewState["ReportPath"] = Request.QueryString["ReportPath"];                    mCommonLogic = new CommonLogic("Report" + ViewState["ReportPath"]);                }                mSqlParameters = (SqlParameter[])Session["Parameters"];                for (int i = 0; i < mSqlParameters.Length; i++)                {                    if (mSqlParameters[i].Value != null && mSqlParameters[i].Value.ToString() == "---請選擇---")                    {                        mSqlParameters[i].Value = DBNull.Value;                    }                }                DataTable aTable = mCommonLogic.ExecFun((SqlParameter[])Session["Parameters"]);                ReportViewer1.Reset();                ReportViewer1.LocalReport.ReportPath = MapPath("~/tab/report/" + ViewState["ReportPath"].ToString() + ".rdlc");                ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource(ViewState["ReportPath"] + "_" + ViewState["ReportPath"], aTable));                if (Session["ReportParams"] != null)                {                    mReportParams = (Microsoft.Reporting.WebForms.ReportParameter[])Session["ReportParams"];                    ReportViewer1.LocalReport.SetParameters(mReportParams);                }                ReportViewer1.LocalReport.Refresh();                Session.Remove("Parameters");                Session.Remove("ReportParams");            }        }

 

 

 

 

 

 

最近在做一個教育相關的項目,遇到很多的報表,在一位學長的推薦下使用了RDLC。

這個系統基本上都是簡單的查詢資料,沒有別的複雜的功能,下簡單記錄下個人使用心得,以便以後使用。

如果能幫到需要瞭解RDLC的人更是非常開心。

 

系統是 三層架構 + 預存程序 開發

資料庫連接字串在Web.Config儲存,經常會改變。

網上很多的RDLC教程都是說資料來源都是說添加資料來源,然後拖過來一個表什麼的,但是這對於實際項目顯然不缺實際,因此需要改變思路。

 

我的方法是:手動添加一個 資料集 Dataset

然後,右擊add->column 添加預存程序或者其他資料來源所查詢到的所有的資料列。

然後添加RDLC報表檔案,功能表列選擇 報表->資料來源

選中建立的DATASET,然後添加到報表。

一般顯示資料都是用表格,故拖出一個表格,在第二行,詳細資料裡右擊選擇運算式。

彈出如下對話方塊。

 

可選內容很多。因為我們制定的是資料集,選擇欄位就可以看到。然後雙擊就得到運算式。

當然也可以選擇其他,比如參數。可以在報表介面 選擇 報表- 報表參數,添加參數。

這裡報表就配置好了。

剩下的就是顯示了。需要一個asp.net空間 ReportViewer.

在適當的時候為它賦資料來源。

代碼如下:

 

private CommonLogic mCommonLogic = null;        private SqlParameter[] mSqlParameters = null;        private Microsoft.Reporting.WebForms.ReportParameter[] mReportParams = null;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                if (Request.QueryString["ReportPath"] != null)                {                    ViewState["ReportPath"] = Request.QueryString["ReportPath"];                    mCommonLogic = new CommonLogic("Report" + ViewState["ReportPath"]);                }                mSqlParameters = (SqlParameter[])Session["Parameters"];                for (int i = 0; i < mSqlParameters.Length; i++)                {                    if (mSqlParameters[i].Value != null && mSqlParameters[i].Value.ToString() == "---請選擇---")                    {                        mSqlParameters[i].Value = DBNull.Value;                    }                }                DataTable aTable = mCommonLogic.ExecFun((SqlParameter[])Session["Parameters"]);                ReportViewer1.Reset();                ReportViewer1.LocalReport.ReportPath = MapPath("~/tab/report/" + ViewState["ReportPath"].ToString() + ".rdlc");                ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource(ViewState["ReportPath"] + "_" + ViewState["ReportPath"], aTable));                if (Session["ReportParams"] != null)                {                    mReportParams = (Microsoft.Reporting.WebForms.ReportParameter[])Session["ReportParams"];                    ReportViewer1.LocalReport.SetParameters(mReportParams);                }                ReportViewer1.LocalReport.Refresh();                Session.Remove("Parameters");                Session.Remove("ReportParams");            }        }

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.