How to: Pass a Hidden Dashboard Parameter to a Custom SQL Query in the Web Viewer
- 3 minutes to read
Important
This documentation applies to v16.2. Starting with v17.1, the ASPxDashboardViewer control is in maintenance mode. In v19.1, the new Web Dashboard Control replaces the old Web Dashboard Viewer. This means that the Web Dashboard Viewer will not be included in our installation packages. See our blog post for more information.
Refer to the following KB articles to learn how to migrate to ASPxDashboard / ASP.NET MVC Dashboard:
ASPxDashboardViewer -> ASPxDashboard
How to migrate from ASPxDashboardViewer to ASPxDashboard working in the ViewerOnly mode
MVCxDashboardViewer -> MVCxDashboard
How to migrate from DashboardViewerExtension to DashboardExtension working in the ViewerOnly mode
The following example shows how to filter a custom SQL query by changing a parameter value in the ASPxDashboardViewer.CustomParameters event handler.
In this example, the custIDQueryParameter query parameter is included in a WHERE clause of a custom SQL query. The custIDQueryParameter parameter is also bound to the hidden custIDDashboardParameter dashboard parameter. The value of this parameter is changed at runtime by handling the ASPxDashboardViewer.CustomParameters event which is raised before the ASPxDashboardViewer sends a query to a database.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-pass-a-hidden-dashboard-parameter-to-a-custom-sql-query-in-the-web-viewer-t338480.
Imports System
Imports System.Linq
Imports DevExpress.DashboardWeb
Imports DevExpress.DataAccess.ConnectionParameters
Namespace Dashboard_CustomParameters_Web
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxDashboardViewer1_CustomParameters(ByVal sender As Object, _
ByVal e As CustomParametersWebEventArgs)
Dim custIDParameter = e.Parameters.FirstOrDefault(Function(p) p.Name = "custIDDashboardParameter")
If custIDParameter IsNot Nothing Then
custIDParameter.Value = "AROUT"
End If
End Sub
Protected Sub ASPxDashboardViewer1_ConfigureDataConnection(ByVal sender As Object, _
ByVal e As ConfigureDataConnectionWebEventArgs)
If e.DataSourceName = "SQL Data Source 1" Then
Dim parameters As Access97ConnectionParameters =
CType(e.ConnectionParameters, Access97ConnectionParameters)
Dim databasePath As String = Server.MapPath("App_Data/nwind.mdb")
parameters.FileName = databasePath
End If
End Sub
End Class
End Namespace