Add custom code with the Code Module in Web Report Designer

The Code Module in Bold Reports® Web Report Designer adds custom code or custom assemblies to a report. The Code Module adds references to custom code embedded in a report or generated with custom assemblies.

How do I add custom code to a report?

You add custom code in Web Report Designer from the Code category of Report Properties, writing the code in Visual Basic (VB).

  1. Click the outer grey surface of the report area, and then click the Properties icon to open the Report Properties. open-properies

  2. The custom code option is listed under the Code category. Click Code… to open the Code Module dialog. report-properies

  3. In the code tab, type the code in the Visual Basic (VB) language. Open code module

  4. The following code example shows a custom function that returns the color string based on the given value range:

    Public Function GetColor(ByVal TotalSales As Decimal) As String
        Dim ColorName As String
        If TotalSales > 0 And TotalSales < 1000 Then
            ColorName = "Yellow"
        ElseIf TotalSales > 1000 And TotalSales < 1500  Then
            ColorName = "Blue"
        ElseIf TotalSales > 2000 Then
            ColorName = "Red"
        Else
            ColorName = "Green"
        End If
        Return ColorName
    End Function

    Enter custom code

  5. Click OK.

  6. Use the following expression to call the custom code function in the report. Call custom code function To learn more about handling expressions, see the Expression section.

  7. To view the color changes based on the price range in a report, click Preview. Preview custom code

How do I add assembly references?

You embed custom assemblies in a Web Report Designer report by creating a simple Visual Studio class library project and defining the required custom functions.

How do I create a custom assembly?

You create a custom assembly for Bold Reports® as a Visual Studio class library that you build into a .dll.

  1. Create a Visual Studio class library. Go to Installed > Visual C#, and then select Class Library (.Net Framework) from the listed templates. Change the application name, and then click OK. To create c sharp class library

  2. Open the class file and create a simple function. To create a simple function

  3. After defining the required functions, build the project. The assembly (.dll) is generated in the bin folder of the respective application.

Note: To embed the custom assembly into the report, the generated assembly must be installed in GAC, or it must be available in the reporting services bin location. We prefer manually copying and pasting the generated custom assembly into the following path: C:\Syncfusion®\Report Server\ReportServer.Web\ReportService\bin.

How do I add references to a custom assembly?

You add a custom assembly reference in the Web Report Designer Code Module from the References tab.

  1. Switch to the References tab. Code module assembly references

  2. To add an Assembly reference, click the Add icon. Add assemby references

  3. Specify the assembly name and click OK. Given assemby references name

How do I add class instances?

You add a class instance in the Web Report Designer Code Module from the Classes tab.

  1. Switch to the Classes tab. Switch to class instance tab

  2. To add a Class instance reference, click the Add icon. Code module class instance

  3. Specify the assembly name and instance name, and click OK. The custom code assembly and instance are now embedded into the report. Added class instance name

  4. Use the following expression to call the embedded custom code function in the report.

    Call the method using expression To learn more about handling expressions, see the Expression section.

  5. To view the color changes based on the price range in a report, click Preview. Preview the record

Download the above report design from the code module sample report on GitHub

Frequently asked questions

Which language does the Code Module use for custom code?

In the code tab of the Web Report Designer Code Module, you type the code in the Visual Basic (VB) language.

Where must a custom assembly be placed?

The generated assembly must be installed in GAC, or it must be available in the reporting services bin location, such as C:\Syncfusion®\Report Server\ReportServer.Web\ReportService\bin.

See also