All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Specify Parameter Values in a Blazor Reporting Application

  • 4 minutes to read

Use the Parameters Panel

Open the Parameters Panel and use its editors to specify parameter values. Click Submit to apply the values to the report and display the document.

Use the Parameters Panel to specify parameter values in a Blazor Reporting application

Use the Document Viewer’s API

The Document Viewer‘s API allows you to use custom UI elements or a URL’s query string to submit parameter values to the report. Create a string that contains the report name and submitted values and pass it to the viewer’s OpenReport method. The following example shows how to do it in a button’s onclick event handler:

View Example

@page "/documentviewer"

<input @bind="paramValue" />

<button @onclick="SubmitParameter">Submit</button>

<DxDocumentViewer ReportName="@reportName" @ref="dxDocumentViewer" Height="1000px" Width="100%">
</DxDocumentViewer>

@code {
    DxDocumentViewer dxDocumentViewer;
    string reportName = "XtraReport1";
    string paramValue = "0";

    void SubmitParameter() {
        string paramName = "strParam";
        string paramQueryString = paramName + "=" + paramValue;

        dxDocumentViewer.OpenReport(reportName + "?" + paramQueryString);
    }
}

When you call the viewer’s OpenReport method, the reporting engine executes a report name resolution service. This service creates a report instance and returns it to the viewer. Implement this service to apply the parameter values to the report. The string argument from the OpenReport method is passed to the service’s method that returns a report instance. In this method, do the following:

  1. Parse the string argument to extract the report name and parameter values.
  2. Create a report instance and apply the parameter values to it. Reference each parameter by name in the report’s Parameters collection and assign the value to the parameter’s Value property.

  3. If you want custom UI elements (or a URL’s query string) to be the only way to submit parameter values, hide the Parameters Panel. To do this, disable the Visible property for all report parameters. If you want users to submit parameter values from both the panel and custom UI elements (or a URL’s query string), disable the report’s RequestParameters property.

  4. Return the report instance.

The example below demonstrates how to apply parameter values to a report in the IReportProvider service’s GetReport method.

public XtraReport GetReport(string id, ReportProviderContext context) {
    // Parse the string with the report name and parameter values.
    string[] parts = id.Split('?');
    string reportName = parts[0];
    string parametersQueryString = parts.Length > 1 ? parts[1] : String.Empty;

    // Create a report instance.
    XtraReport report = null;

    if (reportName == "XtraReport1") {
        report = new XtraReport1();
    } else {
        throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
            string.Format("Could not find report '{0}'.", reportName)
        );
    }

    // Apply the parameter values to the report.
    var parameters = HttpUtility.ParseQueryString(parametersQueryString);

    foreach (string parameterName in parameters.AllKeys) {
        report.Parameters[parameterName].Value = Convert.ChangeType(
            parameters.Get(parameterName), report.Parameters[parameterName].Type);
    }

    // Disable the Visible property for all report parameters
    // to hide the Parameters Panel in the viewer.
    foreach (var parameter in report.Parameters) {
        parameter.Visible = false;
    }

    // If you do not hide the panel, disable the report's RequestParameters property.
    // report.RequestParameters = false;

    return report;
}

The following example shows how to apply parameter values to a report in the ReportStorageWebExtension service’s GetData method.

using System;
using Microsoft.AspNetCore.Hosting;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.Extensions;
using System.Web;
// ...
public override byte[] GetData(string url) {
    try {
        // Parse the string with the report name and parameter values.
        string[] parts = url.Split('?');
        string reportName = parts[0];
        string parametersQueryString = parts.Length > 1 ? parts[1] : String.Empty;

        // Create a report instance.
        XtraReport report = null;

        if (Directory.EnumerateFiles(ReportDirectory).
            Select(Path.GetFileNameWithoutExtension).Contains(reportName)) {
            byte[] reportBytes = File.ReadAllBytes(Path.Combine(ReportDirectory, reportName + FileExtension));
            using (MemoryStream ms = new MemoryStream(reportBytes))
                report = XtraReport.FromStream(ms);
        }

        if (report != null) {
            // Apply the parameter values to the report.
            var parameters = HttpUtility.ParseQueryString(parametersQueryString);

            foreach (string parameterName in parameters.AllKeys) {
                report.Parameters[parameterName].Value = Convert.ChangeType(
                    parameters.Get(parameterName), report.Parameters[parameterName].Type);
            }

            // Disable the Visible property for all report parameters
            // to hide the Parameters Panel in the viewer.
            foreach (var parameter in report.Parameters) {
                parameter.Visible = false;
            }

            // If you do not hide the panel, disable the report's RequestParameters property.
            // report.RequestParameters = false;

            using (MemoryStream ms = new MemoryStream()) {
                report.SaveLayoutToXml(ms);
                return ms.ToArray();
            }
        }
    } catch (Exception ex) {
        throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
            "Could not get report data.", ex);
    }
    throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
        string.Format("Could not find report '{0}'.", url));
}
See Also