Search Results for

    Show / Hide Table of Contents

    Example 4. Calculating total

    In this example, we will show how to calculate the sum by using programming methods. We will use the following:

    • BeforePrint band event;
    • reference to the data column from a script;
    • local variable, whose value will be printed in the report.

    Create a report of the following form:

    In the script, declare the "sum" variable and create a BeforePrint event handler belonging to the band:

    public class ReportScript
    {
      private decimal sum;
    
      private void Data1_BeforePrint(object sender, EventArgs e)
      {
        sum += (Decimal)Report.GetColumnValue("Products.UnitPrice");
      }
    }
    

    The "Products.UnitPrice" data column can be placed into the script, dragging it from the "Data" window.

    If you run the report, you will see the following:

    The same effect can be achieved by using totals.

    Back to top © 1998-2025 Copyright Fast Reports Inc.