重复的子报告不显示参数

时间:2016-08-30 08:40:53

标签: c# crystal-reports

我已多次将3个不同的子报告导入主报告中。我传递了这样的参数:

for (int i = 0; i < rlc.ReportLayout.Count; i++)
{
    if (rlc.ReportLayout[i].SubreportName == "SectionReportTest1.rpt")
    {
        SetSectionOneReportParameters(reportParameterList);
    }
    if (rlc.ReportLayout[i].SubreportName == "SectionReportTest2.rpt")
    {
        SetSectionTwoReportParameters(reportParameterList);
    }
    if (rlc.ReportLayout[i].SubreportName == "SectionReportTest3.rpt")
    {
        SetSectionThreeReportParameters(reportParameterList);
    }
}

不知何故,只有第一份报告似乎得到了参数:

enter image description here

每种颜色代表一个子报告。我缺少什么?

更新

private void SetSectionOneReportParameters(List<ReportParameter> reportParameterList)
{
    reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterOne", SubreportName = "SectionReportTest1.rpt" });
}

private void SetSectionTwoReportParameters(List<ReportParameter> reportParameterList)
{
    reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterTwo", SubreportName = "SectionReportTest2.rpt" });
}

private void SetSectionThreeReportParameters(List<ReportParameter> reportParameterList)
{
    reportParameterList.Add(new ReportParameter() { Name = "SectionParameterID", Value = "ParameterThree", SubreportName = "SectionReportTest3.rpt" });
}

1 个答案:

答案 0 :(得分:0)

使用&#34;共享&#34;声明所有参数在主报告中,您可以在所有子报告中访问它们。

尝试在主报表中声明Shared numbervar myparam,并在要使用它的子报表中重复使用相同的语法,不需要C#。 (如果您仍想使用C#,请使用Crystal报表中的SetParameterValue方法。)

以下是"1.4.3.1.4 To set discrete parameters in a report"的示例:

private void SettingParameters_RD(ReportDocument TestReport)
{
    string PARAMETER_FIELD_NAME = "Country";
    ArrayList countries = new ArrayList();
    countries.Add("Canada");
    countries.Add("USA");
    TestReport.SetParameterValue(PARAMETER_FIELD_NAME, countries.ToArray());
    crystalReportViewer.ReportSource = TestReport;
}

只需在代码中使用此代码,方法是访问子报告:

mainreport.Subreports["subreportname"].SetParameterValue("paramname","values");

您的代码没有编辑子报表的对象和参数集合。这应该纠正

相关问题