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.
usingSystem.Collections.Generic;
usingSystem.Data;
usingSystem.Xml.Linq;
usingDevExpress.DashboardWeb;
namespaceWebDesigner_CustomDashboardStorage {
publicclassCustomDashboardStorage : 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.publicstringAddDashboard(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.publicvoidSaveDashboard(string dashboardID, XDocument dashboard) {
DataRow currentRow = dashboards.Tables[0].Rows.Find(dashboardID);
currentRow["DashboardXml"] = dashboard;
}
}
}
ImportsSystem.Collections.GenericImportsSystem.DataImportsSystem.Xml.LinqImportsDevExpress.DashboardWebNamespace WebDesigner_CustomDashboardStorage
PublicClass CustomDashboardStorage
Implements IEditableDashboardStorage
Private dashboards AsNew 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.PublicFunction AddDashboard(ByVal dashboard As XDocument, ByVal dashboardName AsString) AsStringImplements 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()
EndFunction' Gets information about dashboards available in a DataSet.PublicFunction GetAvailableDashboardsInfo() As IEnumerable(Of DashboardInfo) Implements IEditableDashboardStorage.GetAvailableDashboardsInfo
Dim dashboardInfos AsNew List(Of DashboardInfo)()
ForEach row As DataRow In dashboards.Tables(0).Rows
Dim dashboardInfo AsNew DashboardInfo()
dashboardInfo.ID = row("DashboardID").ToString()
dashboardInfo.Name = row("DashboardName").ToString()
dashboardInfos.Add(dashboardInfo)
Next row
Return dashboardInfos
EndFunction' Loads a dashboard corresponding to the specified ID.PublicFunction LoadDashboard(ByVal dashboardID AsString) 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
EndFunction' Saves the dashboard with the specified ID to a DataSet.PublicSub SaveDashboard(ByVal dashboardID AsString, ByVal dashboard As XDocument) Implements IEditableDashboardStorage.SaveDashboard
Dim currentRow As DataRow = dashboards.Tables(0).Rows.Find(dashboardID)
currentRow("DashboardXml") = dashboard
EndSubEndClassEndNamespace
ImportsSystemImportsDevExpress.DashboardWebNamespace WebDesigner_CustomDashboardStorage
PartialPublicClass WebForm1
Inherits System.Web.UI.Page
PrivateShared dashboardStorage AsNew CustomDashboardStorage()
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
ASPxDashboard1.SetDashboardStorage(dashboardStorage)
EndSubEndClassEndNamespace
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.
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.