标签:pre oom forms img 知识 microsoft close inf c#
本文主要是利用微软自带的控件ReportViewer进行报表设计的小例子
涉及知识点:
效果图如下:
相关代码如下:
1 /// <summary> 2 /// 设置报表 3 /// </summary> 4 private void SetReport() 5 { 6 //第一步:清除之前的数据 7 this.rptView.LocalReport.DataSources.Clear(); 8 //第二步:指定报表路径 9 this.rptView.LocalReport.ReportPath = "Report2.rdlc"; 10 //第三步:构造新的DataTable 11 DataTable dt = new DataTable("DataTable1"); 12 dt.Columns.Add("Name"); 13 dt.Columns.Add("Score"); 14 dt.Columns.Add("Id"); 15 dt.Rows.Add(new object[] { "语文", 80, "Y0001" }); 16 dt.Rows.Add(new object[] { "数学", 75, "S0001" }); 17 dt.Rows.Add(new object[] { "英文", 96, "E0001" }); 18 //名称不能写错,和报表中的数据集名称一致 19 ReportDataSource rdsItem = new ReportDataSource("DataSet1", dt); 20 //此处可以有多个数据源 21 this.rptView.LocalReport.DataSources.Add(rdsItem); 22 //第四步:构造参数 23 List<ReportParameter> lstParameter = new List<ReportParameter>() { 24 new ReportParameter("Title",this.txtTitle.Text), 25 new ReportParameter("Id",this.txtId.Text), 26 new ReportParameter("Name",this.txtName.Text), 27 new ReportParameter("Age",this.txtAge.Text), 28 new ReportParameter("Sex",this.txtSex.Text), 29 new ReportParameter("Salary",this.txtSalary.Text), 30 new ReportParameter("Depart",this.txtDepart.Text) 31 }; 32 this.rptView.LocalReport.SetParameters(lstParameter); 33 this.rptView.ZoomMode = ZoomMode.Percent; 34 this.rptView.ZoomPercent = 100; 35 //第五步:刷新报表 36 this.rptView.RefreshReport(); 37 }
源码下载链接
标签:pre oom forms img 知识 microsoft close inf c#
原文地址:http://www.cnblogs.com/hsiang/p/6896782.html