DashboardConfigurator.DataLoading Event
Namespace: DevExpress.DashboardWeb
Assembly:
DevExpress.Dashboard.v24.2.Web.dll
Declaration
public event DataLoadingWebEventHandler DataLoading
Public Event DataLoading As DataLoadingWebEventHandler
Event Data
The DataLoading event's data class is DataLoadingWebEventArgs.
The following properties provide information specific to this event:
Property |
Description |
DashboardId |
Gets the identifier of the current dashboard.
|
Data |
Gets or sets data for the current data source.
|
DataId |
Gets an object data source’s unique identifier.
|
DataSourceComponentName |
Get the component name of the data source for which the event has been raised.
|
DataSourceName |
Gets the name of the data source for which the event has been raised.
|
OverwriteDataSourceProperty |
Specifies whether the DataSource and DataMember properties of the DashboardObjectDataSource are set when data is supplied in the event handler.
|
Parameters |
Provides access to parameter values passed to the object data source.
|
The DataLoading event is raised when the dashboard needs to load data from a data source assigned using the DashboardObjectDataSource. Use the event parameter’s DataLoadingEventArgs.Data property to provide data for this data source. This object should implement the IEnumerable or IListSource interface.
For other data source types (for instance, DashboardSqlDataSource or DashboardOlapDataSource), you can handle the DashboardConfigurator.ConfigureDataConnection event to customize connection parameters.
Example
This example shows how to bind the ASP.NET MVC Dashboard extension to the Object Data Source and supply it with data using the DashboardConfigurator.DataLoading
event. To use the created data source, run the application and create a new dashboard.
@{
ViewBag.Title = "Index";
}
<div style="position: absolute; left: 0; right: 0; top:0; bottom:0;">
@Html.DevExpress().Dashboard(settings => {
settings.Name = "Dashboard";
settings.Width = Unit.Percentage(100);
settings.Height = Unit.Percentage(100);
}).GetHtml()
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>@ViewBag.Title</title>
@Html.DevExpress().GetStyleSheets(
new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
new StyleSheet { ExtensionSuite = ExtensionSuite.GridView },
new StyleSheet { ExtensionSuite = ExtensionSuite.Dashboard }
)
@Html.DevExpress().GetScripts(
new Script { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
new Script { ExtensionSuite = ExtensionSuite.Editors },
new Script { ExtensionSuite = ExtensionSuite.GridView },
new Script { ExtensionSuite = ExtensionSuite.Dashboard }
)
</head>
<body>
@RenderBody()
</body>
</html>
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DashboardWeb.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Web.Routing;
public class DashboardConfig {
public static void RegisterService(RouteCollection routes) {
routes.MapDashboardRoute();
DashboardConfigurator.Default.SetDashboardStorage(new DashboardFileStorage(@"~/App_Data/"));
var dataSourceStorage = new DataSourceInMemoryStorage();
DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage);
DashboardObjectDataSource objDataSource = new DashboardObjectDataSource("Object Data Source");
objDataSource.DataSource = typeof(SalesPersonData);
dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml());
DashboardConfigurator.Default.DataLoading += Default_DataLoading;
}
private static void Default_DataLoading(object sender, DataLoadingWebEventArgs e) {
if (e.DataSourceName == "Object Data Source") {
e.Data = CreateData();
}
}
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" };
for (int i = 0; i < 100; i++) {
SalesPersonData record = new SalesPersonData();
int seed = (int)DateTime.Now.Ticks & 0x0000FFFF;
record.SalesPerson = salesPersons[new Random(seed).Next(0, salesPersons.Length)];
record.Quantity = new Random(seed).Next(0, 100);
data.Add(record);
Thread.Sleep(3);
}
return data;
}
}
public class SalesPersonData {
public string SalesPerson { get; set; }
public int Quantity { get; set; }
}
Imports System.Threading
Imports System.Web.Routing
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Imports DevExpress.DashboardWeb.Mvc
Public Class DashboardConfig
Public Shared Sub RegisterService(ByVal routes As RouteCollection)
routes.MapDashboardRoute()
DashboardConfigurator.Default.SetDashboardStorage(New DashboardFileStorage("~/App_Data/"))
Dim dataSourceStorage = New DataSourceInMemoryStorage()
DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage)
Dim objDataSource As New DashboardObjectDataSource("Object Data Source")
objDataSource.DataSource = GetType(SalesPersonData)
dataSourceStorage.RegisterDataSource("objDataSource", objDataSource.SaveToXml())
AddHandler DashboardConfigurator.Default.DataLoading, AddressOf Default_DataLoading
End Sub
Private Shared Sub Default_DataLoading(ByVal sender As Object, ByVal e As DataLoadingWebEventArgs)
If e.DataSourceName = "Object Data Source" Then
e.Data = CreateData()
End If
End Sub
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"}
For i As Integer = 0 To 99
Dim record As New SalesPersonData()
Dim seed As Long = CLng(Date.Now.Ticks) And &HFFFF
record.SalesPerson = salesPersons((New Random(seed)).Next(0, salesPersons.Length))
record.Quantity = (New Random(seed)).Next(0, 100)
data.Add(record)
Thread.Sleep(3)
Next i
Return data
End Function
End Class
Public Class SalesPersonData
Public Property SalesPerson() As String
Public Property Quantity() As Integer
End Class
@{
ViewBag.Title = "Index";
}
<div style="position: absolute; left: 0; right: 0; top:0; bottom:0;">
@Html.DevExpress().Dashboard(settings => {
settings.Name = "Dashboard";
settings.Width = Unit.Percentage(100);
settings.Height = Unit.Percentage(100);
}).GetHtml()
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>@ViewBag.Title</title>
@Html.DevExpress().GetStyleSheets(
new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
new StyleSheet { ExtensionSuite = ExtensionSuite.GridView },
new StyleSheet { ExtensionSuite = ExtensionSuite.Dashboard }
)
@Html.DevExpress().GetScripts(
new Script { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
new Script { ExtensionSuite = ExtensionSuite.Editors },
new Script { ExtensionSuite = ExtensionSuite.GridView },
new Script { ExtensionSuite = ExtensionSuite.Dashboard }
)
</head>
<body>
@RenderBody()
</body>
</html>
The following code snippets (auto-collected from DevExpress Examples) contain references to the DataLoading event.
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.
See Also