Using Data Binding Events

  • 2 minutes to read

The ASPxTreeView control implements specific data-binding events - ASPxTreeView.NodeDataBound and ASPxDataWebControlBase.DataBound. They allow you to perform custom operations at specific times in the data binding process.

The NodeDataBound event occurs immediately after an individual TreeViewNode object has been automatically created, and its properties have been initialized with values retrieved from the corresponding data fields. You can add functionality to your application within a handler of the NodeDataBound event, by accessing the data bound node via the event argument's TreeViewNodeEventArgs.Node property, and modify its settings, as required. Also, the TreeViewNode.DataItem property can be used to access the node's corresponding data item object, and any data field value can be obtained.

The DataBound event is invoked to notify you that any data binding logic used by the ASPxTreeView control has completed. This event occurs after all data items of the specified data source have been processed and the corresponding TreeViewNode objects have been added. You can also implement additional logic at this moment, by providing a handler to the DataBound event.

The following example demonstrates how the NodeDataBound event can be used.

In this code, the ASPxTreeView is bound to an XML file using a standard XmlDataSource component. The ASPxTreeView's TextField, ImageUrlField, and NavigateUrlField properties are used to specify the names of data item attributes from which the corresponding node settings should be obtained. The NodeDataBound event is handled to change the text style of nodes which represent classes (their text is displayed in bold).

using DevExpress.Web.ASPxTreeView;
using System.Xml;

public partial class TreeView_DataBinding : Page {
    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {

    protected void treeView_NodeDataBound(object source, TreeViewNodeEventArgs e) {
        XmlNode dataNode = ((e.Node.DataItem as IHierarchyData).Item as XmlNode);
        if (dataNode.Name == "class")
            e.Node.TextStyle.Font.Bold = true;

The picture shows the view in a browser

TreeView - Binding Events

See Also