2

我有一个名为的业务对象"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();

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

4

1 回答 1

1

遵循此代码:>>

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();

这里 Subreport Even 处理程序代码

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)));
}

如果您需要创建钻取报告,请点击此链接单击此处查看钻取报告

于 2012-04-30T07:15:27.130 回答