System.Web.UI.WebControls.TreeView.DataBindings Property

Gets a collection of System.Web.UI.WebControls.TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to.

Syntax

[System.ComponentModel.MergableProperty(false)]
[System.ComponentModel.DefaultValue(null)]
[System.ComponentModel.Editor("System.Web.UI.Design.WebControls.TreeViewBindingsEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public TreeNodeBindingCollection DataBindings { get; }

Value

Documentation for this section has not yet been entered.

Remarks

The TreeView.DataBindings collection contains System.Web.UI.WebControls.TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to. 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 System.Web.UI.WebControls.TreeNode object. The criteria indicate when a data item should be bound to a node. The criteria 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 System.Web.UI.WebControls.TreeNodeBinding objects are defined that conflict with each other, the System.Web.UI.WebControls.TreeView control applies the tree node bindings in the following order of precedence:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

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 System.Web.UI.WebControls.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 System.Web.UI.WebControls.TreeNode object to a value, see System.Web.UI.WebControls.TreeNodeBinding.

Although the TreeView.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 System.Web.UI.WebControls.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 TreeView.AutoGenerateDataBindings property of the System.Web.UI.WebControls.TreeView control to true, the bindings that are created have the TreeNodeBinding.PopulateOnDemand property set to true. Data bindings that are created declaratively have the TreeNodeBinding.PopulateOnDemand property set to false. Using the declarative syntax allows you to control the behavior of individual data bindings.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0