FastReport.NET 动态创建报表FastReport.Report实例绑定List<T>数据源
FastReport.NET 动态创建报表FastReport.Report实例绑定List参考代码
C# Code:
/// <summary>
/// 创建报表对象
/// </summary>
/// <param name="listDataSource">数据源</param>
/// <returns>返回报表实例</returns>
private FastReport.Report CreateReport(List<_Demo_Customer> listDataSource)
{
string rptFileName = "rpt_Demo_Customer.frx";
string rptTitle = "2345234234";
//报表模板文件路径
string reportTemplateFile = Path.Combine(Application.StartupPath, @"Reports\" + rptFileName);
//实例报表对象,加载报表模板文件
FastReport.Report report = new FastReport.Report();
report.Load(reportTemplateFile);
//注册数据源
report.RegisterData(listDataSource, "M");
//给DataBand数据列表绑定数据源
DataBand dataBand = report.FindObject("Data1") as DataBand;
DataSourceBase dataSource = report.GetDataSource("M");
dataSource.Enabled = true;//必须设置为true
dataBand.DataSource = dataSource;
//设置报表参数
report.Parameters.FindByName("pReportTitle").Value = rptTitle;
report.Parameters.FindByName("pPrintUser").Value = Loginer.CurrentUser.AccountName;
report.Parameters.FindByName("pPrintTime").Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
return report;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 创建报表对象
/// </summary>
/// <param name="listDataSource">数据源</param>
/// <returns>返回报表实例</returns>
private FastReport.Report CreateReport(List<_Demo_Customer> listDataSource)
{
string rptFileName = "rpt_Demo_Customer.frx";
string rptTitle = "2345234234";
//报表模板文件路径
string reportTemplateFile = Path.Combine(Application.StartupPath, @"Reports\" + rptFileName);
//实例报表对象,加载报表模板文件
FastReport.Report report = new FastReport.Report();
report.Load(reportTemplateFile);
//注册数据源
report.RegisterData(listDataSource, "M");
//给DataBand数据列表绑定数据源
DataBand dataBand = report.FindObject("Data1") as DataBand;
DataSourceBase dataSource = report.GetDataSource("M");
dataSource.Enabled = true;//必须设置为true
dataBand.DataSource = dataSource;
//设置报表参数
report.Parameters.FindByName("pReportTitle").Value = rptTitle;
report.Parameters.FindByName("pPrintUser").Value = Loginer.CurrentUser.AccountName;
report.Parameters.FindByName("pPrintTime").Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
return report;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
注意事项
1. 数据绑定数据源对象类型(DataBand.DataSource):FastReport.Data.BusinessObjectDataSource
2. dataSource.Enabled = true;//必须设置为true,数据源才有效!
打印预览
C# Code:
public void Preview(Form owner, List<_Demo_Customer> data)
{
FastReport.Report report = CreateReport(data);
report.Show(true, owner);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
FastReport.Report report = CreateReport(data);
report.Show(true, owner);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761

参考文档:
FastReport.NET 2023使用DataTable报表数据源配置JsonDataSourceConnection连接|C/S开发框架
FastReport.NET 2023使用DataTable报表数据源配置MsSqlDataConnection连接|C/S开发框架
FastReport.NET2023报表数据源配置详解|C/S开发框架
C# DevExpress TreeListLookUpEdit 绑定数据源下拉窗体
DevExpress TreeList 自动加载数据源并显示漂亮图标
DEV CheckedListBoxControl组件绑定数据源
FastReport.NET制作动态栏位列报表C#实例
FastReport.NET v2021 主从表报表打印图片 | 开发框架
FastReport.NET v2021 打印动态图片报表 | 软件开发平台
为什么FastReport.NET v2021 打印预览只显示一条记录 | 软件开发平台
FastReport.NET v2021 打印预览报表出错NullReferenceException / RestoreEncodedText,踩坑!
FastReport.NET2023 报表设计器|FastReport教程|C/S开发框架
C/S架构软件开发平台旗舰版V6.0 | 使用FastReport.NET制作二维码报表|C/S开发框架
踩坑日记 | DevExpress GridControl设置DataSource数据源无效|C/S开发框架
DataGridView绑定List 对象,偶尔出现索引 |1 没有值|C/S开发框架
VS2022+FastReport.NET 安装环境支持
FastReport.NET 2023使用DataTable报表数据源配置JsonDataSourceConnection连接|C/S开发框架
FastReport.NET 2023使用DataTable报表数据源配置MsSqlDataConnection连接|C/S开发框架
FastReport.NET2023报表数据源配置详解|C/S开发框架
C# DevExpress TreeListLookUpEdit 绑定数据源下拉窗体
DevExpress TreeList 自动加载数据源并显示漂亮图标
DEV CheckedListBoxControl组件绑定数据源
FastReport.NET制作动态栏位列报表C#实例
FastReport.NET v2021 主从表报表打印图片 | 开发框架
FastReport.NET v2021 打印动态图片报表 | 软件开发平台
为什么FastReport.NET v2021 打印预览只显示一条记录 | 软件开发平台
FastReport.NET v2021 打印预览报表出错NullReferenceException / RestoreEncodedText,踩坑!
FastReport.NET2023 报表设计器|FastReport教程|C/S开发框架
C/S架构软件开发平台旗舰版V6.0 | 使用FastReport.NET制作二维码报表|C/S开发框架
踩坑日记 | DevExpress GridControl设置DataSource数据源无效|C/S开发框架
DataGridView绑定List 对象,偶尔出现索引 |1 没有值|C/S开发框架
VS2022+FastReport.NET 安装环境支持
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
在线客服
