我正在导入相同的报告3次。对于每次迭代,我传递的是不同的值,但问题是只有第一个导入的报告获取值,其他两个为空。这是我的代码:
foreach (var current in reportParameterList)
{
if (string.IsNullOrEmpty(current.SubreportName))
{
document.SetParameterValue(current.Name, current.Value);
}
else
{
document.SetParameterValue(current.Name, current.Value, current.SubreportName);
}
}
因此,对于子报表名称为空白的地方,即主报表,其他情况是我的子报表。因此,导入3次的相同报告不会显示第二个和第三个的值。
更新
填充子报告值的方法:
for (int i = 0; i < _reportLayoutConfiguration.ReportLayout.Count; i++)
{
if (_reportLayoutConfiguration.ReportLayout[i].SubreportName == "SectionReportTest1.rpt")
{
SetSectionOneReportParameters(reportParameterList);
}
if (_reportLayoutConfiguration.ReportLayout[i].SubreportName == "SectionReportTest2.rpt")
{
SetSectionTwoReportParameters(reportParameterList);
}
if (_reportLayoutConfiguration.ReportLayout[i].SubreportName == "SectionReportTest3.rpt")
{
SetSectionThreeReportParameters(reportParameterList);
}
}
private void SetSectionOneReportParameters(List<ReportParameter> reportParameterList)
{
reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterOne_" + DateTime.Now.ToLongTimeString() + "", SubreportName = "SectionReportTest1.rpt" });
}
private void SetSectionTwoReportParameters(List<ReportParameter> reportParameterList)
{
reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterTwo_" + DateTime.Now.ToLongTimeString() + "", SubreportName = "SectionReportTest2.rpt" });
}
private void SetSectionThreeReportParameters(List<ReportParameter> reportParameterList)
{
reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterThree_" + DateTime.Now.ToLongTimeString() + "", SubreportName = "SectionReportTest3.rpt" });
}
当然,这仅用于测试。