Skip to main content
A newer version of this page is available. .

How to: Pass a Hidden Dashboard Parameter to a Custom SQL Query in the ASP.NET Web Forms Dashboard Control

  • 3 minutes to read

The following example shows how to override an initial or user-defined dashboard parameter value by changing it in the CustomParameters event handler.

The effective parameter value is hidden from the end-user, and if you set the DashboardParameter.Visible property to false, the parameter itself will also be hidden.

The dashboard in this example has a parameter named CustomerIdDashboardParameter which has a specific initial value. At runtime, its value is changed in the SetInitialDashboardState event handler. This value is displayed in the Dashboard Parameters dialog and can be changed by the end-user, However, by handling the ASPxDashboard.CustomParameters event, we can validate the parameter value and ignore the value provided by the end-user.

To accomplish this, the data is obtained using a custom SQL query with a parameter named CustomerIdParameter. The query parameter is bound to the CustomerIdDashboardParameter dashboard parameter. The value of this parameter is changed at runtime by handling the ASPxDashboard.CustomParameters event which is raised before the ASPxDashboard sends a query to a database. Thus, only the value passed in the ASPxDashboard.CustomParameters event is in effect.

Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Imports System
Imports System.Linq

Namespace ASPxDashboard_CustomParameters
    Partial Public Class WebForm1
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ASPxDashboard1.DashboardXmlPath = Server.MapPath("App_Data/dashboard1.xml")
        End Sub
        Protected Sub ASPxDashboard1_SetInitialDashboardState(ByVal sender As Object, ByVal e As SetInitialDashboardStateEventArgs)
            e.InitialState = InitializeDashboardState()
        End Sub

        Public Function InitializeDashboardState() As DashboardState
            Dim dashboardState As New DashboardState()
            Dim parameterState As New DashboardParameterState("CustomerIdDashboardParameter", "XXX", GetType(String))
            dashboardState.Parameters.Add(parameterState)
            Return dashboardState
        End Function

        Protected Sub ASPxDashboard1_CustomParameters(ByVal sender As Object, ByVal e As CustomParametersWebEventArgs)
            Dim custIDParameter = e.Parameters.FirstOrDefault(Function(p) p.Name = "CustomerIdDashboardParameter")
            If custIDParameter IsNot Nothing Then
                custIDParameter.Value = "AROUT"
            End If
        End Sub
    End Class
End Namespace