ASPxTreeList.DataSource Property

Gets or sets the ASPxTreeList's data source.

Namespace: DevExpress.Web.ASPxTreeList

Assembly: DevExpress.Web.ASPxTreeList.v20.2.dll


public override object DataSource { get; set; }

Property Value

Type Description

An object which represents the data source from which the ASPxTreeList retrieves its data.


This example shows how to bind the ASPxTreeList to data created at runtime.


To correctly restore from the ViewState, a tree list needs data. When binding to data created at runtime, you must bind the tree list within the Page_Init event. Don't handle the Page_Load event because it is fired after the ViewState has been restored.

using System.Data.OleDb;
using DevExpress.Web.ASPxTreeList;

public partial class _Default : System.Web.UI.Page {
    protected override void OnInit(EventArgs e) {

    protected void Page_Load(object sender, EventArgs e) {
        (ASPxTreeList1 as IPostBackDataHandlerEx).ForceLoadPostData(Tree.ID, HttpContext.Current.Request.Params);

    OleDbDataAdapter CreateDataAdapter() {
        string connectionString =
        @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\Departments.mdb";
        OleDbConnection myConnection = new OleDbConnection(connectionString);
        string query =
        "SELECT [ID], [ParentID], [Department], [Budget], [Location] FROM [Departments]";
        return new OleDbDataAdapter(query, myConnection);
    DataTable CreateDataTable(OleDbDataAdapter myAdapter) {
        DataTable dt = new DataTable();
        DataSet testData = new DataSet();
        return testData.Tables[0];
    void InitTreeList(ASPxTreeList tl) {
        tl.SettingsSelection.Recursive = true;
        tl.SettingsSelection.AllowSelectAll = true;
        tl.SettingsSelection.Enabled = true;
        tl.KeyFieldName = "ID";
        tl.ParentFieldName = "ParentID";
        tl.DataSource = CreateDataTable(CreateDataAdapter());
See Also