Skip to main content

ASPxTreeList.DataSource Property

Gets or sets the ASPxTreeList’s data source.

Namespace: DevExpress.Web.ASPxTreeList

Assembly: DevExpress.Web.ASPxTreeList.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public override object DataSource { get; set; }

Property Value

Type Description
Object

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

Example

To bind an ASPxTreeList control to data created at runtime, handle the Page_Init or Page_Load event. In the event handler, assign a data source to the tree list’s DataSource property and call the DataBind() method:

<dx:ASPxTreeList ID="ASPxTreeList1" runat="server"></dx:ASPxTreeList>
using DevExpress.Web.ASPxTreeList;
using DevExpress.Web.Internal;
using System;
using System.Data;
using System.Data.OleDb;
using System.Web;

public partial class _Default : System.Web.UI.Page {

    protected override void Page_Init(EventArgs e) {
        InitTreeList(ASPxTreeList1);
        ASPxTreeList1.DataBind();
    }

    private void InitTreeList(ASPxTreeList tl) {
        tl.SettingsSelection.AllowSelectAll = true;
        tl.SettingsSelection.Enabled = true;
        tl.KeyFieldName = "ID";
        tl.ParentFieldName = "ParentID";
        tl.DataSource = CreateDataTable(CreateDataAdapter());
    }

    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();
        myAdapter.Fill(testData);
        return testData.Tables[0];
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DataSource property.

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