分享

[原创] RDLC 报表系列(五) RDLC报表分组 - 大熊的空间 - 博客园

 唐伯龙 2011-05-04

[原创] RDLC 报表系列(五) RDLC报表分组

本文只代表作者在一定阶段的认识与理解。

写作前提

在我的博客园中我写了关于一些RDLC报表的使用,请参考这里。因为没有时间,所以没有导入到我的个人博客中。在博客园中相关文章如下:

二、本文内容

  1. 加载RDLC报表数据
  2. 实现数据分组
  3. 总结
  4. 代码下载(下载

三、加载RDLC报表数据

我们的示例是要从学生表中,取出200条学生信息,然后加载到RDLC报表中。

01 using System;
02 using System.Collections;
03 using System.Configuration;
04 using System.Data;
05 using System.Linq;
06 using System.Web;
07 using System.Web.Security;
08 using System.Web.UI;
09 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12 using System.Data.SqlClient;
13 using System.Collections.Generic;
14 using System.Xml.Linq;
15 using Microsoft.Reporting.WinForms;
16 using RCLC.DataEntity;
17  
18 namespace RCLC
19 {
20     public partial class _Default : CustomPageBase
21     {
22         protected void Page_Load(object sender, EventArgs e)
23         {
24  
25         }
26  
27         protected void ButtonReportGenerate_Click(object sender, EventArgs e)
28         {
29             List<ReportDataSource> reportDataSource = new List<ReportDataSource>();
30             RportDataSet ds = new RportDataSet();
31             string templatePath = string.Empty;
32             string totalRecords = string.Empty;
33  
34             //获得数据
35             SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LoggingConnectionString"].ConnectionString);
36             SqlCommand command = conn.CreateCommand();
37             command.CommandType = CommandType.Text;
38             command.CommandText = "SELECT TOP 200 * FROM T_STUDENT";
39             SqlDataAdapter da = new SqlDataAdapter(command);
40             da.Fill(ds.T_STUDENT);
41  
42             //指定报表模板
43             templatePath = "ReportTemplate/StudentReport.rdlc";
44  
45             //把获取的数据集合提供给在报表中名为RportDataSet_T_STUDENT数据集
46             reportDataSource.Add(new ReportDataSource("RportDataSet_T_STUDENT", ds.T_STUDENT));
47             List<ReportParameter> parameterList = new List<ReportParameter>();
48             ////Generate Report, 报表可以生成PDF,EXCEL及以其它形式,根据需求去设置
49             GetReportMultipleDataSourceFile(reportDataSource, templatePath, parameterList, "pdf");
50         }
51     }
52 }
上面的代码已经获取到200条学生的信息,然后把数据从数据库中取出然后加载到StudentReport.rdlc报表中,下面要做的事情就是对数据进行分组了。

四、实现分组

下面我们根据学生的性别进行分组,步骤如下:

  • 打开RDLC模板文件,点击报表的行标签,然后点击“插入分组(Insert Group)”

  • 在插入分组的窗口中,我们选择需要分组字段(这里的学生的性别),如下图所示

  • 插入分组后,我们可以为分组加一标题,标题就是性别

这样我们就已经分组结束了,下面我们要做的就是看看如果如何。

你也可以从这里下载PDF结果(下载)。

五、总结

通过上面的示例我们学会了如何使用RDLC分组功能实现功能,通过上面的示例我们插入了一个性别的分组,当然也可以分组中再插入子分组,以实现二级、三级或者N级分组。

当然可以对分组进行统计等一系列功能。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多