How to: Specify Default Parameter Values in the Web Viewer

Note

Starting with v17.1, we recommend using the ASPxDashboard control or a corresponding ASP.NET MVC extension to display dashboards within web applications. Refer to the following KB articles to learn more about migration to ASPxDashboard / ASP.NET MVC Dashboard:

The following example shows how to specify default parameter values on dashboard loading. To do this, handle the ASPxDashboardViewer.DashboardLoaded event, get access to the dashboard object using the DashboardLoadedWebEventArgs.Dashboard event parameter and specify the default value(s) using the Dashboard.Parameters["parameterName"].Value property.

The ASPxDashboardViewer.ConfigureDataConnection event is handled to customize connection settings before the ASPxDashboardViewer connects to a data store.

using System;
using System.Collections.Generic;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.ConnectionParameters;

namespace WebViewer_DefaultParameterValues {
    public partial class WebForm1 : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
        }

        protected void ASPxDashboardViewer1_DashboardLoaded(object sender, DashboardLoadedWebEventArgs e) {
            // Specifies default parameter values.
            e.Dashboard.Parameters["customerIdParameter"].Value = new List<string>() { "ALFKI", "AROUT", "BONAP" };
        }

        protected void ASPxDashboardViewer1_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
            if (e.DataSourceName == "SQL Data Source 1")
                e.ConnectionParameters = new Access97ConnectionParameters(Server.MapPath("App_Data/nwind.mdb"), "", "");
        }
    }
}