System.Web.UI.WebControls Namespace TreeView Class
.NET Framework version 2.0
Returns a collection of TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to.
Script |
[ TreeNodeBindingCollection variable = ] TreeView.DataBindings |
variable |
Returns a TreeNodeBindingCollection that represents the relationship between a data item and the node that it is binding to. |
The property is read/write with no default value.
Use the DataBindings collection to programmatically obtain information about each TreeNodeBinding object that defines the relationship between a data item and the node that it is binding to in a TreeView control. This collection is typically used to iterate through all the bindings, or to access a specific binding in the tree.
When binding to a data source where each data item contains multiple properties ( such as an XML element with several attributes ), a node displays the value that is returned by the ToString ( ) method of the data item, by default.
In the case of an XML element, the node displays the element name, which shows the underlying structure of the tree, but is not very useful otherwise. You can bind a node to a specific data item property by specifying tree node bindings.
When defining the relationship between a data item and a node, you must specify both the criteria for binding and the values to bind to the properties of the TreeNode object. The criteria indicate when a data item should be bound to a node, and can be specified with a node depth, a data member, or both.
A node depth specifies the node level that gets bound. For example, if you specify a node depth of 0, all nodes in the tree structure at level 0 are bound using the tree node binding.
A data member specifies the type of the data item in the underlying data source, but can represent different information depending on the data source. For example, the data member for an XML element specifies the name of the element.
If multiple TreeNodeBinding objects are defined that conflict with each other, the TreeView control applies the tree node bindings in the following order of precedence:
- The TreeNodeBinding object that defines both a depth and a data member.
- The TreeNodeBinding object that defines only the depth.
- The TreeNodeBinding object that defines only the data member.
- The TreeNodeBinding object that defines neither the depth nor the data member.
If multiple bindings are specified that meet the same precedence criteria, the first binding in the collection is applied.
Once the binding criteria is established, you can then bind a property of a TreeNode object that can be bound to a value. You can either bind to an attribute or field of a data item or display a static value. For more information on binding the properties of a TreeNode object to a value, see the TreeNodeBinding class.
Although the DataBindings collection can be programmatically populated, it is usually set declaratively. To specify the tree node bindings, first nest opening and closing <DataBindings> tags between the opening and closing tags of the TreeView control. Next, place <asp:TreeNodeBinding> elements between the opening and closing <DataBindings> tags for each tree node binding you want to specify.
When data bindings are created by setting the AutoGenerateDataBindings property of the TreeView control to true, the bindings that are created have the PopulateOnDemand property set to true.
Data bindings that are created declaratively have the PopulateOnDemand property set to false. Using the declarative syntax allows you to control the behavior of individual data bindings.
TreeView Members AutoGenerateDataBindings TreeNodeBinding