[]
        
(Showing Draft Content)

Report Render Mode

You can customize the report layout, and control the data returned based on different render modes as per your requirement by using the UserContext.GetRenderMode function from the expression editor under Miscellaneous. UserContext.GetRenderMode function returns the render mode for previewing, printing, or exporting.

The examples below will show how to:

  • Control Report Preview Limit

  • Customize the Report Content

Example 1: Control Report Preview Limit

In this example, we have used this function to display:

  • Only a controllable number of rows while previewing the report.

  • When exporting or printing the report, you can print or export it in full.

Follow the steps mentioned below to set the report preview limit:

  1. On the report designer, drag and drop the table control and bind it to a dataset. Here in this example, we have used a server dataset Northwind.

  2. Write the following query for the dataset, click Validate, and click OK.

    SELECT {IIF(UserContext.GetRenderMode() = "preview", "TOP " & @PreviewLimit & " * ", " * ")} FROM orders

    edit query for dataset


  3. Click the Add button to add a parameter.


    add parameter

  4. On the Edit Parameter section, enter the Name as PreviewLimit. Under the Default Value section, select Source as Non-Queried and set the value to 2.

    edit parameter


    Parameter PreviewLimit is added.

  5. Now preview the report. You can set the preview limit through the PreviewLimit parameter. The default value is set to 2. Also, as in this example, there is no limit for export, so you will be able to view all the data on the exported file.


    previewlimit gif

    You can also use nested SQL queries for setting different limits for print, preview, and export as shown below:

    SELECT {IIF(UserContext.GetRenderMode() = "preview", "TOP " & @PreviewLimit & "", IIF(UserContext.GetRenderMode() = "export", "TOP " & @export & "", IIF(UserContext.GetRenderMode() = "print", "TOP " & @print & "", "")))} FROM orders )

Example 2: Customize Report Content

In this example, we have used this function to display different images when printing, exporting, and previewing the report.

Follow the steps mentioned below to customize the report:

  1. On the report designer, drag and drop the table control and bind it to a dataset. Here in this example, we have used a server dataset Northwind.

  2. Write the following query for the dataset, click Validate, and click OK.

    select * from orders

    edit dataset


  3. Click the Add button to add a parameter.

    image


  4. We will add two parameters in this example. On the Edit Parameter section, enter the Name as Parameter1. Under the Available Values section, select Source as From Query. Select Data Set Name, Value Field, and Label Field. Under Default Value, select the From Query option and select Data Set Name and Value Field as shown below.

    edit parameter1


  5. Add Parameter2. On the Edit Parameter section, enter the Name as Parameter2. Under the Available Values section, select Source as From Query. Select Data Set Name, Value Field, and Label Field. Under Default Value, select the From Query option and select Data Set Name and Value Field as shown below.

    edit parameter 2


  6. In the table, for the field OrderId, add the expression as shown below.


    orderid expression

  7. Drag two image controls, upload the images, and add the following expressions to display different images for print, preview, and export.

    Expression for image 1

    image 1 expression


    Expression for image 2

    image 2 expression_1

  8. Drag a TextBox and add the following expression.


    textbox expression


    So, the final layout of the report is shown below.

    report layout

    9. Preview the report.

  • For preview, the report will display the image of 2 Apples.


    On preview

  • When you Print the report, it will display the image of 2 Watermelons.


    print image

  • When you export the report, it will display one apple, and one watermelon as we have not set any expression for export.


    export image


    So, you can customize different content, and styles for previewing, exporting, and printing according to your requirements using the UserContext.GetRenderMode function.

    Note: You can use the function {UserContext.GetRenderMode()} with the following report controls: TextBox, Table, Chart, and Tablix.