水晶报表填充.Net Objects数据源
Crystal Reports(水晶报表)是一款商务智能(BI)软件,主要用于设计及产生报表。是业内最专业、功能最强的报表系统。
查看网络资料及课本图书,鲜有介绍通过.NET Objects作为数据源填充水晶报表的示例。本文将通过两个简单的示例演示水晶报表填充.Net Objects数据源的过程。
示例一:打印学生信息(一个.NET Objects数据源的填充)
示例效果:

Student.cs
using System;
using System.Collections.Generic;
using System.Web;
namespace CrystalReportsDemo
{
public class Student
{
public Student(string studentNo,string studentName,string sex,int age)
{
this.StudentNo = studentNo;
this.StudentName = studentName;
this.Sex = sex;
this.Age = age;
}
public string StudentNo
{ set; get; }
public string StudentName
{ set; get; }
public string Sex
{ get; private set; }
public int Age
{ get; private set; }
}
}
将其编译后,即可通过数据库专家将其作为数据源导入到字段资源管理器。

绘制报表样式并插入数据库字段:

在Default.aspx页面拖入CrystalReportViewer控件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CrystalReportsDemo._Default" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="crvReport" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CrystalReportsDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillReport();
}
private void FillReport()
{
List<Student> studentList = new List<Student>();
studentList.Add(new Student("200901001", "学生一", "男", 23));
studentList.Add(new Student("200901002", "学生二", "男", 24));
studentList.Add(new Student("200901003", "学生三", "女", 22));
studentList.Add(new Student("200901004", "学生四", "男", 23));
studentList.Add(new Student("200901005", "学生五", "女", 25));
studentList.Add(new Student("200901006", "学生六", "男", 23));
CrStudents studentsReport = new CrStudents();
studentsReport.SetDataSource(studentList);
crvReport.ReportSource = studentsReport;
}
}
}
示例二:打印学生成绩(多个.NET Objects数据源的填充)
示例效果:

Subject.cs
using System;
using System.Collections.Generic;
using System.Web;
namespace CrystalReportsDemo
{
public class Subject
{
public Subject(string subjectName,string subjectType,double result,string comment)
{
this.SubjectName = subjectName;
this.SubjectType = subjectType;
this.Result = result;
this.Comment = comment;
}
public string SubjectName
{ set; get; }
public string SubjectType
{ set; get; }
public double Result
{ set; get; }
public string Comment
{ set; get; }
}
}
主报表:(CrSupReport.rpt)

子报表:(CrSubReport.rpt)

Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="CrystalReportsDemo.Default2" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="crvReport2" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
</html>
Default2.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalReportsDemo
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillReport();
}
private void FillReport()
{
List<Student> studentList = new List<Student>();
studentList.Add(new Student("200901001", "学生一", "男", 23));
ReportDocument supReport = new CrSupReport();
supReport.SetDataSource(studentList);
crvReport2.ReportSource = supReport;
List<Subject> subjectList = new List<Subject>();
subjectList.Add(new Subject("语文","文科",90,"评语"));
subjectList.Add(new Subject("数学", "理科", 90, "评语"));
subjectList.Add(new Subject("工程学", "工科", 80, "评语"));
subjectList.Add(new Subject("现代医学", "医学", 90, "评语"));
ReportDocument subReport = supReport.Subreports["CrSubReport"];
subReport.SetDataSource(subjectList);
}
}
}
水晶报表填充.Net Objects数据源的更多相关文章
- MS SQL自定义函数IsPositiveInteger MS SQL自定义函数IsNumeric 水晶报表使用IEnumerable<T>数据源
MS SQL自定义函数IsPositiveInteger 判断字符串是否为正整数,0开始的的数字不算. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...
- 水晶报表使用IEnumerable<T>数据源
这篇我们学习水晶报表,报表呈现的数据源是IEnumerable<T>.比如下面的数据: using System; using System.Collections.Generic; us ...
- WinForm中使用CrystalReport水晶报表——基础,分组统计,自定义数据源
开篇 本篇文章主要是帮助刚开始接触CrystalReport报表的新手提供一个循序渐进的教程.该教程主要分为三个部分1)CrystalReport的基本使用方法:2)使用CrystalReport对数 ...
- c# 水晶报表的设计(非常的基础)
最近在公司实习,由于公司需要用到的一种叫做水晶报表的神奇的东东,老大就叫我们学习学习.怕自己以后忘了,也为了以后阅读方便,将其记录下来. 使用工具:vs2008 基本方法一.使用水晶报表的推模式 步骤 ...
- 水晶报表(web)表格信息展示
一.环境安装 开发工具使用VS2010+SAP Crystal Reports13_0+.NETformwork4.0 因为vs2010已经不再集成水晶报表,所以需要我们去找合适的版本下载http:/ ...
- asp.net实现通用水晶报表
此片博文是在你有一定水晶报表基础的前提下参阅的:如果对于水晶报表的基础知识比较薄弱建议先去了解下水晶报表: 因为项目需要,研究了下水晶报表.说实在,这个组件很强大,但是用起来也很麻烦.刚开始使用遇到了 ...
- 水晶报表初体验(Visual Studio 2010)
安装水晶报表后如下使用: 配置rpt文件,如图 前台(Asp.net页面): <%@ Register Assembly="CrystalDecisions.Web, Version= ...
- 水晶报表连接Oracle做数据报表笔记
首先,新建一个水晶报表的文件,这个时候要给这个报表文件绑定一个oracle数据源, 选择右侧菜单的这个东西,选择“数据库专家”,打开之后是这么一个界面: 选择建立新连接: 这个地方最关键,也是我为什么 ...
- 用C#代码控制水晶报表中的对象
在C#代码中调用水晶报表的各个对象:字段对象:FieldObject obj=(FieldObject)oRpt.ReportDefinition.ReportObjects["FieldO ...
随机推荐
- 解决 IE6 背景缓存
解决 IE6 背景缓存 <!--[if IE 6]><script type="text/javascript">document.execCommand( ...
- Selenium2(WebDriver)总结(三)---元素定位方法
元素定位的重要性不言而喻,如果定位不到元素谈何操作元素呢,webdrvier提供了很多种元素定位方法,如ID,Name,xpath,css,tagname等. 例如需要定位如下元素: <inpu ...
- Linux中查看磁盘容量
一.命令 df -hl 二.效果 [root@cq-test-master ambari]# df -hl Filesystem Size Used Avail Use% Mounted on /de ...
- Mysql中使用Group_Concat将列组合进来。
一.上例子: ) as CityId,group_concat(stationId) ,NameCn from `wd-area` where type='cn3k' and areaId like ...
- postman发送get请求
在地址栏里输入请求url(用到拼接方式):http://127.0.0.1:8081/getuser?userid=1 选择“GET”方式, 点击“send”得到json数据如图 分类: post ...
- Python学习笔记七:pip
安装pip: 到github上下载pip:https://github.com/pypa/pip 解压后,在解压出来的文件夹中打开命令行,输入 python setup.py install 安装完毕 ...
- 【Java多线程】线程同步方法概览
一:使用syncrhoized内置锁实现同步 使用互斥来实现线程间的同步,保证共享数据在同一时刻只被一个线程使用.Java中最基本的互斥手段就是syncrhoized关键字. syncrhoized的 ...
- JAVA & Android 等待线程池内任务全部完成后退出
void shutdownAndAwaitTermination(ExecutorService pool) { pool.shutdown(); // Disable new tasks from ...
- nodejs直接调用grunt(非调用批处理)
在windows下,我们做js构建工作,都习惯安装grunt-cli,只需要命令行grunt...一切构建工作都自动完成了.这已经是很完美的情况了,不过最近要做一个服务器版的自动化构建系统,在node ...
- Aspect实现对方法日志的拦截记录
在实际的业务系统中,我们通常都希望程序自动的打印方法的入参和返回值,某些特定的方法可能不想打印返回值(返回数据过大,打印日志影响效率),特有了下面的实现. 1.忽略返回值的java注解类 import ...