Tree Generation Algorithm in the ASPxTreeList

  • 2 min to read

The ASPxTreeList is designed to answer the needs of all ASP.NET developers who face the challenge of rendering hierarchical data structures.

The nodes in a tree represent data source records. The Root node is a parent node for all nodes displayed within the ASPxTreeList. This is a special node which isn't displayed within the ASPxTreeList. The collection of its child nodes can be accessed via the ASPxTreeList.Nodes property. Nodes contained within this collection are displayed as root nodes within the ASPxTreeList.

To build a tree, a tree list's data source should contain two additional fields.

  • Key Field

    This field must contain unique values. This field must be assigned to the ASPxTreeList.KeyFieldName property.

  • Parent Field

    This field must contain values that indicate parent nodes, and the key values for the current node. It should be assigned to the ASPxTreeList.ParentFieldName property.

    By default, if this value doesn't point to any other node, the node is added to the ASPxTreeList.Nodes collection, as you see with the first node displayed in the image below. Otherwise, the node is added to its parent's TreeListNode.ChildNodes collection.

    However, if you specify the ASPxTreeList.RootValue property's value, only those nodes whose parent field value matches the ASPxTreeList.RootValue are added to the collection of root nodes. If the node's parent field value doesn't match the ASPxTreeList.RootValue and doesn't point to any other node, this node isn't displayed within the ASPxTreeList.

Important: the data types of the KeyField and ParentField fields must be the same.

 

The image below illustrates an example of an appropriate data source:

cdTreeGeneration

 

Concepts

Task-Based Help