Managing number of records per page in ActiveReports subreport

As in every reporting system, one of the problems that you often meet in DataDynamics ActiveReports is how to control number of records in the subreport that will be displayed on the page.

 The actual problem I had was following: on a financial document (order list), I had to create report, which contains 2 subreports with the materials list. Because of the nature of the document, I had to have header and footer on every page. Further more, a user must have thepossibility to print more order lists at once in the report. Now, since the subreport cannot control page header and footer, we had to implement that in the report, and to limit number of the records in the subreport on 15 per page (that's how many records can fit). Additional request was that it is obligatory that, if one oder list spreads accross more pages (more than 15 records!), at the end of every page (except the last one!) there is a text "Continued on the next page".

 So the report would look something like

PAGE 1:
Order list 1 starts
Header
First 15 records of the order list 1
"Continued on the next page" text
Footer

PAGE 2:
Order list 1 continues
Header
Next 15 records
"Continued on the next page" text
Footer

Page 3
Order list 1 contunues
Header
remaining n records ot the order list 1
Order list 1 ends (summary row!)
Footer

Page 4
Order list 2 starts
Header
First 15 records of the order list 2
"Continued on the next page" text
Footer

Page 5
Order list 2 contunues
Header
remaining n records ot the order list 2
Order list 2 ends (summary row!)
Report ends (grand total row!)
Footer

 The only way as I saw it can be done was to use ActiveReports Script to control number of the records per page in the detail section of the subrecord, and to control "Continued on the next page" text by changing the height of the detail section dynamicaly. ActiveReports Script is a very nice feature of the ActiveReports, where you can save the C# code directly in the report file, and then, in the runtime, this code is on-the-fly compiled an executed.

Detail section was created with a datarow, and, below it a textbox with text "Continued on the next page".

The ActiveReports script for that subreport was:

public void ActiveReport_DataInitialize()
{
       //add a counter field for the number of the records
       //directly in the activereports script

       rpt.Fields.Add ("counterField");
}

public void Detail_Format()
{
       //convert a field value to integer
       int sl = System.Convert.ToInt32(rpt.Fields["counterField"].Value);

       if (sl!=0 && ((sl%15)==0)) {
              // if the current record number is modulus of 15
              //(15 records per page!) and it is not the first record
              // than force the page break

              DataDynamics.ActiveReports.Detail subReportDetail =
              (DataDynamics.ActiveReports.Detail)(rpt.Sections["Detail"]);
              subReportDetail.NewPage = DataDynamics.ActiveReports.NewPage.After;

             
              // increase the height of the detail section to 0,9 inches
              //that the text "Continued on the next page" will be displayed

              subReportDetail.Height = (float)(0.9);

       }
       else
       {
              //the record is not modulus of 15, do not break page
              DataDynamics.ActiveReports.Detail subReportDetail =
              (DataDynamics.ActiveReports.Detail)(rpt.Sections["Detail"]);
              subReportDetail.NewPage = DataDynamics.ActiveReports.NewPage.None;

              //decrease the detail height so that the text
              //"Continued on the next page" hides

              subReportDetail.Height = (float)(0.3);
        }

        //increase the record counter
        sl = sl+1;
        rpt.Fields["counterField"].Value = sl;
}

Published Friday, February 23, 2007 1:16 PM by Adis Jugo
Filed under: , ,