In this example, the ObjectDataSource.DataSource property specifies the type of a data class. The actual data for this data source is provided by handling the ASPxDashboard.DataLoading event.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebDesigner_DataLoading.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v16.2.Web, Version=16.2.1.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" Width="100%" Height="100%"
ondataloading="ASPxDashboard1_DataLoading"></dx:ASPxDashboard>
</div>
</form>
</body>
</html>
using System;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
namespace WebDesigner_DataLoading {
public partial class Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards");
ASPxDashboard1.SetDashboardStorage(dashboardFileStorage);
DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
objDataSource.DataSource = typeof(SalesPersonData);
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml());
ASPxDashboard1.SetDataSourceStorage(dataSourceStorage);
}
protected void ASPxDashboard1_DataLoading(object sender, DataLoadingWebEventArgs e) {
if (e.DataSourceName == "Object Data Source") {
e.Data = SalesPersonData.CreateData();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Threading;
namespace WebDesigner_DataLoading {
public class SalesPersonData {
public string SalesPerson { get; set; }
public int Quantity { get; set; }
public static List<SalesPersonData> CreateData() {
List<SalesPersonData> data = new List<SalesPersonData>();
string[] salesPersons = { "Andrew Fuller", "Michael Suyama",
"Robert King", "Nancy Davolio",
"Margaret Peacock", "Laura Callahan",
"Steven Buchanan", "Janet Leverling" };
var rnd = new Random();
for(int i = 0; i < 100; i++) {
SalesPersonData record = new SalesPersonData();
record.SalesPerson = salesPersons[rnd.Next(0, salesPersons.Length)];
record.Quantity = rnd.Next(0, 100);
data.Add(record);
}
return data;
}
}
}
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebDesigner_DataLoading.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v16.2.Web, Version=16.2.1.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" Width="100%" Height="100%"
ondataloading="ASPxDashboard1_DataLoading"></dx:ASPxDashboard>
</div>
</form>
</body>
</html>
Imports System
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Namespace WebDesigner_DataLoading
Partial Public Class [Default]
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim dashboardFileStorage As New DashboardFileStorage("~/App_Data/Dashboards")
ASPxDashboard1.SetDashboardStorage(dashboardFileStorage)
Dim objDataSource As New DashboardObjectDataSource("Object Data Source")
objDataSource.DataSource = GetType(SalesPersonData)
Dim dataSourceStorage As New DataSourceInMemoryStorage()
dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml())
ASPxDashboard1.SetDataSourceStorage(dataSourceStorage)
End Sub
Protected Sub ASPxDashboard1_DataLoading(ByVal sender As Object, ByVal e As DataLoadingWebEventArgs)
If e.DataSourceName = "Object Data Source" Then
e.Data = SalesPersonData.CreateData()
End If
End Sub
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Threading
Namespace WebDesigner_DataLoading
Public Class SalesPersonData
Public Property SalesPerson() As String
Public Property Quantity() As Integer
Public Shared Function CreateData() As List(Of SalesPersonData)
Dim data As New List(Of SalesPersonData)()
Dim salesPersons() As String = {"Andrew Fuller", "Michael Suyama",
"Robert King", "Nancy Davolio",
"Margaret Peacock", "Laura Callahan",
"Steven Buchanan", "Janet Leverling"}
Dim rnd = New Random()
For i As Integer = 0 To 99
Dim record As New SalesPersonData()
record.SalesPerson = salesPersons(rnd.Next(0, salesPersons.Length))
record.Quantity = rnd.Next(0, 100)
data.Add(record)
Next i
Return data
End Function
End Class
End Namespace