c# - 如何使用业务对象绑定(bind) rdlc 报告?

标签 c# rdlc

我有一个名为 "TeamMaster" 的业务对象, 我在其中定义了三个属性,Id、Name 和 Flg。 在我的 .rdlc 报告中,我将 TeamMaster 对象用作数据源, 现在我在表单的页面加载事件中编写以下代码,在其中添加报表查看器控件并将我的报表定义为本地报表。

using (RDLC_DEMO_DBEntities objdatabase = new RDLC_DEMO_DBEntities())
        {
            lstTeamMstr = objdatabase.TeamMasters.ToList();
        }
        this.TeamMasterBindingSource.DataSource = lstTeamMstr;
        this.reportViewer1.RefreshReport();

当我使用调试检查此代码时,我在 TeamBindingSource 中获得了 6 条记录, 但在 windows 报告中只显示六个空白行, 有什么问题吗?

最佳答案

遵循这段代码:>>

string path = HttpContext.Current.Server.MapPath(Your Report path);
ReportViewer1.Reset(); //important
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;

// Add sub report even handler if you need  
***ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportProcessingEventHandler);***
LocalReport objReport = ReportViewer1.LocalReport;
objReport.ReportPath = path;
// Add Parameter If you need 
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("Name", Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();

//Add Datasourdce
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = "Datasource Name Used due to report design";
reportDataSource.Value = DataSourceValue(Your object data-source);
objReport.DataSources.Add(reportDataSource);
objReport.Refresh();

这里是子报表偶处理程序代码

private void MySubreportProcessingEventHandler(object sender,  SubreportProcessingEventArgs e)
{
 //You can get parameter from main report 
int paramname = int.Parse(e.Parameters[0].Values[0].ToString());
//You can also add parameter in sub report if you  need like main report

//Now add sub report data source     
 e.DataSources.Add(new ReportDataSource("DataSource Name",DataSourceValue)));
}

如果您需要创建钻取报告,请访问此链接 Click here for Drillthrough report

关于c# - 如何使用业务对象绑定(bind) rdlc 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10007944/

相关文章:

c# - Task.Run 什么时候流 SynchronizationContext 和 ExecutionContext?

c# - 该进程无法访问该文件,因为它正被另一个进程使用 : Correct way to read\write to a file: heavily used application-Part II

sorting - RDLC 报告没有按照我告诉它的方式排序

c# - .Net Core 1.x 项目在升级到 VS 2017 后无法启动

c# - .NET 动态方法。最棒的表演

javascript - JavaScript 中带偏移量的 GZip 解压

c# - 根据子集合总结一个属性

whitespace - 在rdlc文件中隐藏文本框时保留空白

asp.net - 如何在 RDLC 报告中使用舍入函数时删除小数点后的零?

visual-studio-2010 - 如何在 VS 2012 Express 中重新设计旧的 .rdlc 报告?