dashboard-devexpress-dot-dashboardweb-dot-aspxdashboard-dot-setdashboardstorage-x28-devexpress-dot-dashboardweb-dot-idashboardstorage-x29.md
Specifies a custom storage of dashboards for the Web Dashboard.
Namespace : DevExpress.DashboardWeb
Assembly : DevExpress.Dashboard.v25.2.Web.WebForms.dll
NuGet Package : DevExpress.Web.Dashboard
public void SetDashboardStorage(
IDashboardStorage dashboardStorage
)
Public Sub SetDashboardStorage(
dashboardStorage As IDashboardStorage
)
| Name | Type | Description |
|---|---|---|
| dashboardStorage | IDashboardStorage |
An object implementing the IDashboardStorage interface that is the custom storage of dashboards.
|
The following example shows how to create a custom dashboard storage for ASPxDashboard by implementing the IEditableDashboardStorage interface. In this example, a DataSet is used as an in-memory storage of dashboards. This DataSet can be used later to save dashboards in the database using DataAdapter.
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
namespace WebDesigner_CustomDashboardStorage
{
public class DashboardStorageDataSet: DataSet
{
public DashboardStorageDataSet()
{
DataTable table = new DataTable("Dashboards");
DataColumn idColumn = new DataColumn("DashboardID", typeof(Int32));
idColumn.AutoIncrement = true;
idColumn.AutoIncrementSeed = 1;
idColumn.Unique = true;
idColumn.AllowDBNull = false;
table.Columns.Add(idColumn);
table.Columns.Add("DashboardXml", typeof(string));
table.Columns.Add("DashboardName", typeof(string));
table.PrimaryKey = new DataColumn[] {idColumn};
this.Tables.Add(table);
}
}
}
using System;
using DevExpress.DashboardWeb;
namespace WebDesigner_CustomDashboardStorage {
public partial class WebForm1 : System.Web.UI.Page {
static CustomDashboardStorage dashboardStorage = new CustomDashboardStorage();
protected void Page_Load(object sender, EventArgs e) {
ASPxDashboard1.SetDashboardStorage(dashboardStorage);
}
}
}
using System.Collections.Generic;
using System.Data;
using System.Xml.Linq;
using DevExpress.DashboardWeb;
namespace WebDesigner_CustomDashboardStorage {
public class CustomDashboardStorage : IEditableDashboardStorage {
DashboardStorageDataSet dashboards = new DashboardStorageDataSet();
// Adds a dashboard with the specified ID and name to a DataSet.
// Note that the 'DashboardID' column is an auto-increment column that is used to store unique dashboard IDs.
public string AddDashboard(XDocument dashboard, string dashboardName) {
DataRow newRow = dashboards.Tables[0].NewRow();
newRow["DashboardName"] = dashboardName;
newRow["DashboardXml"] = dashboard;
dashboards.Tables[0].Rows.Add(newRow);
return newRow["DashboardID"].ToString();
}
// Gets information about dashboards available in a DataSet.
public IEnumerable<DashboardInfo> GetAvailableDashboardsInfo() {
List<DashboardInfo> dashboardInfos = new List<DashboardInfo>();
foreach (DataRow row in dashboards.Tables[0].Rows) {
DashboardInfo dashboardInfo = new DashboardInfo();
dashboardInfo.ID = row["DashboardID"].ToString();
dashboardInfo.Name = row["DashboardName"].ToString();
dashboardInfos.Add(dashboardInfo);
}
return dashboardInfos;
}
// Loads a dashboard corresponding to the specified ID.
public XDocument LoadDashboard(string dashboardID) {
DataRow currentRow = dashboards.Tables[0].Rows.Find(dashboardID);
XDocument dashboardXml = XDocument.Parse(currentRow["DashboardXml"].ToString());
return dashboardXml;
}
// Saves the dashboard with the specified ID to a DataSet.
public void SaveDashboard(string dashboardID, XDocument dashboard) {
DataRow currentRow = dashboards.Tables[0].Rows.Find(dashboardID);
currentRow["DashboardXml"] = dashboard;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebDesigner_CustomDashboardStorage.WebForm1" %>
<%@ Register Assembly="DevExpress.Dashboard.v24.2.Web.WebForms, Version=24.2.13.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.DashboardWeb" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="position:absolute; left:0; right:0; top:0; bottom:0;">
<dx:ASPxDashboard ID="ASPxDashboard1" runat="server" AllowExportDashboard="True"
Height="100%" Width="100%"></dx:ASPxDashboard>
</div>
</form>
</body>
</html>
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Web
Namespace WebDesigner_CustomDashboardStorage
Public Class DashboardStorageDataSet
Inherits DataSet
Public Sub New()
Dim table As New DataTable("Dashboards")
Dim idColumn As New DataColumn("DashboardID", GetType(Int32))
idColumn.AutoIncrement = True
idColumn.AutoIncrementSeed = 1
idColumn.Unique = True
idColumn.AllowDBNull = False
table.Columns.Add(idColumn)
table.Columns.Add("DashboardXml", GetType(String))
table.Columns.Add("DashboardName", GetType(String))
table.PrimaryKey = New DataColumn() {idColumn}
Me.Tables.Add(table)
End Sub
End Class
End Namespace
Imports System.Collections.Generic
Imports System.Data
Imports System.Xml.Linq
Imports DevExpress.DashboardWeb
Namespace WebDesigner_CustomDashboardStorage
Public Class CustomDashboardStorage
Implements IEditableDashboardStorage
Private dashboards As New DashboardStorageDataSet()
' Adds a dashboard with the specified ID and name to a DataSet.
' Note that the 'DashboardID' column is an auto-increment column that is used to store unique dashboard IDs.
Public Function AddDashboard(ByVal dashboard As XDocument, ByVal dashboardName As String) As String Implements IEditableDashboardStorage.AddDashboard
Dim newRow As DataRow = dashboards.Tables(0).NewRow()
newRow("DashboardName") = dashboardName
newRow("DashboardXml") = dashboard
dashboards.Tables(0).Rows.Add(newRow)
Return newRow("DashboardID").ToString()
End Function
' Gets information about dashboards available in a DataSet.
Public Function GetAvailableDashboardsInfo() As IEnumerable(Of DashboardInfo) Implements IEditableDashboardStorage.GetAvailableDashboardsInfo
Dim dashboardInfos As New List(Of DashboardInfo)()
For Each row As DataRow In dashboards.Tables(0).Rows
Dim dashboardInfo As New DashboardInfo()
dashboardInfo.ID = row("DashboardID").ToString()
dashboardInfo.Name = row("DashboardName").ToString()
dashboardInfos.Add(dashboardInfo)
Next row
Return dashboardInfos
End Function
' Loads a dashboard corresponding to the specified ID.
Public Function LoadDashboard(ByVal dashboardID As String) As XDocument Implements IEditableDashboardStorage.LoadDashboard
Dim currentRow As DataRow = dashboards.Tables(0).Rows.Find(dashboardID)
Dim dashboardXml As XDocument = XDocument.Parse(currentRow("DashboardXml").ToString())
Return dashboardXml
End Function
' Saves the dashboard with the specified ID to a DataSet.
Public Sub SaveDashboard(ByVal dashboardID As String, ByVal dashboard As XDocument) Implements IEditableDashboardStorage.SaveDashboard
Dim currentRow As DataRow = dashboards.Tables(0).Rows.Find(dashboardID)
currentRow("DashboardXml") = dashboard
End Sub
End Class
End Namespace
Imports System
Imports DevExpress.DashboardWeb
Namespace WebDesigner_CustomDashboardStorage
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Private Shared dashboardStorage As New CustomDashboardStorage()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ASPxDashboard1.SetDashboardStorage(dashboardStorage)
End Sub
End Class
End Namespace
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="WebForm1.aspx.vb"
Inherits="WebDesigner_CustomDashboardStorage.WebForm1" %>
<%@ Register Assembly="DevExpress.Dashboard.v24.2.Web.WebForms, Version=24.2.13.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.DashboardWeb" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="position:absolute; left:0; right:0; top:0; bottom:0;">
<dx:ASPxDashboard ID="ASPxDashboard1" runat="server" AllowExportDashboard="True"
Height="100%" Width="100%"></dx:ASPxDashboard>
</div>
</form>
</body>
</html>
The following code snippets (auto-collected from DevExpress Examples) contain references to the SetDashboardStorage(IDashboardStorage) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards");
ASPxDashboardObjectDS.SetDashboardStorage(dashboardFileStorage);
protected void Page_Load(object sender, EventArgs e) {
ASPxDashboard1.SetDashboardStorage(new CustomDashboardStorage());
}
web-forms-dashboard-save-dashboards-title-as-file-name/CS/DXWebApplication2/Default.aspx.cs#L12
CustomFileStorage newDashboardStorage = new CustomFileStorage(@"~/App_Data/Dashboards");
ASPxDashboard1.SetDashboardStorage(newDashboardStorage);
ASPxDashboard1.SetDashboardStorage(SessionDashboardStorage.Instance);
web-forms-dashboard-enable-export-in-data-inspector/CS/WebForm1.aspx.cs#L11
DashboardFileStorage newDashboardStorage = new DashboardFileStorage(HostingEnvironment.MapPath(@"~/App_Data/Dashboards"));
ASPxDashboard1.SetDashboardStorage(newDashboardStorage);
Dim dashboardFileStorage As DashboardFileStorage = New DashboardFileStorage("~/App_Data/Dashboards")
ASPxDashboardObjectDS.SetDashboardStorage(dashboardFileStorage)
' Uncomment the next line to allow users to create new data sources based on predefined connection strings.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ASPxDashboard1.SetDashboardStorage(New CustomDashboardStorage())
End Sub
web-forms-dashboard-save-dashboards-title-as-file-name/VB/DXWebApplication2/Default.aspx.vb#L15
Dim newDashboardStorage As CustomFileStorage = New CustomFileStorage("~/App_Data/Dashboards")
ASPxDashboard1.SetDashboardStorage(newDashboardStorage)
' Uncomment this string to allow end users to create new data sources based on predefined connection strings.
ASPxDashboard1.SetDashboardStorage(SessionDashboardStorage.Instance)
web-forms-dashboard-enable-export-in-data-inspector/VB/WebForm1.aspx.vb#L13
Dim newDashboardStorage As New DashboardFileStorage(HostingEnvironment.MapPath("~/App_Data/Dashboards"))
ASPxDashboard1.SetDashboardStorage(newDashboardStorage)
See Also