我有一个名为 "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/