简体   繁体   中英

Using Subreport in Crystal Report and ASP.NET C#

My main Report and SubReport is very similar to each other, using same parameters and formula the only difference is their order in the derails section. Now When I load the subreport in the report and run it, ASP.NET keeps on asking to enter values for the parameters used.

在此处输入图片说明

I think I need to have a code that loads the subreport.

 protected void Page_Load(object sender, EventArgs e)
    {        

       report.Load(Server.MapPath("MonthlySalesReportP.rpt"));


        report.SetDatabaseLogon
          ("sa", "pw", @"databasename, "servername");  

        CrystalReportViewer1.ReportSource = report;
        CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
        CrystalReportViewer1.DataBind();
        CrystalReportViewer1.SeparatePages = false;



        report.SetParameterValue(0, MonthLastYear);
        report.SetParameterValue(1, MonthCurrent);
        report.SetParameterValue(2, MonthPrevious);
        report.SetParameterValue(3, RP);
        report.SetParameterValue(4, Loc);
        report.SetParameterValue(5, cms);
        report.SetParameterValue(6, YearCurrent);
        report.SetParameterValue(7, YearPrevious);
        report.SetParameterValue(8, YearLastYear);
        report.SetParameterValue(9, FullName);


}

Should I include a code that is needed to read the subreport?

I see this suggestion

report.SetDataSource(dtproductview);
report.Subreports[0].SetDataSource(dsHeader.Tables[0]);
report.Subreports[1].SetDataSource(dsFooter.Tables[0]);

But i do not have a datatable or dataset, it is directly from a stored procedure

  1. Have you tried Linking the parameters of the subreport to the main report?

    ( Change subreport links in Subreport context menu)

  2. You can try, also:

    report.Subreports[0].SetParameterValue(0, MonthLastYear);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM