C#利用ReportViewer生成報(bào)表
本文主要是利用微軟自帶的控件ReportViewer進(jìn)行報(bào)表設(shè)計(jì)的小例子,具體內(nèi)容如下
涉及知識(shí)點(diǎn):
ReportViewer :位于Microsoft.Reporting.WinForms命名空間, 主要用于報(bào)表的顯示
Report:報(bào)表,以rdlc結(jié)尾的文件,可視化設(shè)計(jì)報(bào)表模板。
報(bào)表數(shù)據(jù):內(nèi)置字段,參數(shù),圖像,數(shù)據(jù)集(本報(bào)表主要使用參數(shù),和數(shù)據(jù)集)
ReportParameter:使用名稱和值實(shí)例化新的報(bào)表參數(shù)
ReportDataSource:報(bào)表的數(shù)據(jù)源與DataTable對(duì)象聯(lián)系起來
效果圖如下:

相關(guān)代碼如下:
/// <summary>
/// 設(shè)置報(bào)表
/// </summary>
private void SetReport()
{
//第一步:清除之前的數(shù)據(jù)
this.rptView.LocalReport.DataSources.Clear();
//第二步:指定報(bào)表路徑
this.rptView.LocalReport.ReportPath = "Report2.rdlc";
//第三步:構(gòu)造新的DataTable
DataTable dt = new DataTable("DataTable1");
dt.Columns.Add("Name");
dt.Columns.Add("Score");
dt.Columns.Add("Id");
dt.Rows.Add(new object[] { "語文", 80, "Y0001" });
dt.Rows.Add(new object[] { "數(shù)學(xué)", 75, "S0001" });
dt.Rows.Add(new object[] { "英文", 96, "E0001" });
//名稱不能寫錯(cuò),和報(bào)表中的數(shù)據(jù)集名稱一致
ReportDataSource rdsItem = new ReportDataSource("DataSet1", dt);
//此處可以有多個(gè)數(shù)據(jù)源
this.rptView.LocalReport.DataSources.Add(rdsItem);
//第四步:構(gòu)造參數(shù)
List<ReportParameter> lstParameter = new List<ReportParameter>() {
new ReportParameter("Title",this.txtTitle.Text),
new ReportParameter("Id",this.txtId.Text),
new ReportParameter("Name",this.txtName.Text),
new ReportParameter("Age",this.txtAge.Text),
new ReportParameter("Sex",this.txtSex.Text),
new ReportParameter("Salary",this.txtSalary.Text),
new ReportParameter("Depart",this.txtDepart.Text)
};
this.rptView.LocalReport.SetParameters(lstParameter);
this.rptView.ZoomMode = ZoomMode.Percent;
this.rptView.ZoomPercent = 100;
//第五步:刷新報(bào)表
this.rptView.RefreshReport();
}
源碼下載鏈接
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
深入分析緩存依賴中cachedependency對(duì)象及周邊小講
本篇文章是對(duì)緩存依賴中cachedependency對(duì)象進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PowerShell 定時(shí)執(zhí)行.Net(C#)程序的方法
利用PowerShell可以調(diào)用動(dòng)態(tài)頁面,然后再用 .bat 執(zhí)行 PowerShell 腳本,最后把 .bat 添加到服務(wù)器的任務(wù)計(jì)劃里面。OK,所有操作都做好了,.Net 定時(shí)執(zhí)行了,是不是呢,有木有呢。2013-04-04
C#實(shí)現(xiàn)多種圖片格式轉(zhuǎn)換的示例詳解
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)多種圖片格式轉(zhuǎn)換,例如轉(zhuǎn)換成圖標(biāo)圖像ICO,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01

