Standalone Report Designer
Search results

Code Module

Code Module is used to add a custom code or custom assemblies to a report. Code module allows to add references to custom code embedded in a report or generated with custom assemblies.

Add Custom Code to a report

  1. Click the outer grey surface report area and then click the Properties icon to open Report Properties. open-properies
  2. The custom code option is listed under the Code category, click Code… to open Code Module dialog. report-properies
  3. In the code tab, type the codes in Visual Basic (VB) language. Open code module
  4. The following code example demonstrates the 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"
            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 Refer Expression section to learn more about handling expressions.
  7. To view the color changes based on the price range in a report, click Preview. Preview custom code

Add Assembly References

To embed a custom assemblies in a report, create a simple visual studio class library project and define the required custom functions.

Create a custom assembly

  1. Create a visual studio class library. Go to Installed > Visual C#, and then select Class Library (.Net Framework) from the listed template, change the application name, and then click OK. To create c sharp class library
  2. Open the class file, create a simple function as shown below. To create a simple function
  3. After defining the required functions, build the project. Now, the assembly(.dll) will be 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 reporting services bin location. We prefer to manually copy and paste the generated custom assembly into the following path C:\Syncfusion\Report Server\ReportServer.Web\ReportService\bin.

Adding a references to custom assembly

  1. Switch to the References tab. Code module assembly references
  2. To add a Assembly references, Click on the Add icon. Add assemby references
  3. Specify the assembly name and click OK. Given assemby references name

Add Class instances

  1. Switch to the Classes tab. Switch to class instance tab
  2. To add a Class instance reference, Click on the Add icon. Code module class instance
  3. Specify the assembly name, instance name and click OK. Now, the custom code assembly and instance are 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 Refer Expression section to learn more about handling expressions.

  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 link