RDLC 文件中的自定义数据源

Custom Data Source in RDLC file

我创建了一个 RDLC 文件,其中我将数据table 用于 ReportDataSource,但现在我想使用数据的自定义分类 table 请为此提供建议

 ReportDataSource reportDataSource = new ReportDataSource();



   reportDataSource.Name = "DataSet1"; // Name of the DataSet we set in .rdlc

            reportDataSource.Value = dt;// Datatable 

            reportViewer.LocalReport.ReportPath = // Path of the rdlc file

您可以在 数据源配置向导 select select Object[=24 中添加数据集时向项目添加新报表/报表向导=] 并按照向导和 select 您的数据模型创建报告。

然后将报告查看器放在表单上,​​并从智能标签 windows(单击报告查看器右上角的小箭头)选择您的报告,您将看到 BindingSource 将添加到表单, 此绑定源将用作报表的数据源。

要将数据传递给您的报表,在表单的加载事件中,您可以将 List<DataModel> 传递给绑定源,然后 call this.reportViewer1.RefreshReport();

更多信息您可以查看: Walkthrough: Using a Business Object Data Source with the ReportViewer Windows Forms Control in Local Processing Mode

首先,您必须从您的自定义 class.

创建数据
ReportDataSource reportDataSource = new ReportDataSource
{
    Name = "DataSet1",
    Value = data
};
rpvAllReportViewer.LocalReport.DataSources.Add(reportDataSource );
rpvAllReportViewer.LocalReport.ReportEmbeddedResource = //your report Path

如果有

则添加参数
ReportParameter parameter1 = new ReportParameter("ParameterName1", parameter1Value);
rpvAllReportViewer.LocalReport.SetParameters(new[] { parameter1 });
rpvAllReportViewer.RefreshReport();