我创建了一个RDLC文件,其中我使用数据表作为ReportDataSource但现在我想使用数据表的自定义classinsted请为此提出建议
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
答案 0 :(得分:1)
您可以向项目添加新的报告/报告向导,在数据源配置向导中添加数据集时,选择对象,然后按照向导选择您的数据模型和创建报告。
然后在表单上放置一个报表查看器并从智能标记窗口(单击报表查看器右上角的小箭头)选择您的报表,您将看到BindingSource
将添加到表单中,此绑定源将是用作报告的数据来源。
要将数据传递到您的报告,请在表单的加载事件中将List<DataModel>
传递给绑定源,然后call this.reportViewer1.RefreshReport();
答案 1 :(得分:0)
首先,您必须从自定义类创建数据。
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();