Defines the relationship between a data item and the node it is binding to in a System.Web.UI.WebControls.TreeView control.
See Also: TreeNodeBinding Members
When the System.Web.UI.WebControls.TreeView control is bound to a data source where each data item contains multiple fields (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 the properties of a node to a specific field by specifying tree node bindings. A System.Web.UI.WebControls.TreeNodeBinding object defines the relationship between each data item and the node that it is binding to.
The System.Web.UI.WebControls.TreeView control stores its System.Web.UI.WebControls.TreeNodeBinding objects in the TreeView.DataBindings property and applies the bindings to the data source to create a one-to-one relationship between the tree hierarchy and the data source hierarchy. For each data item in the data source, the System.Web.UI.WebControls.TreeView control attempts to match the data item to a System.Web.UI.WebControls.TreeNodeBinding object in order to create the corresponding System.Web.UI.WebControls.TreeNode object.
When creating a System.Web.UI.WebControls.TreeNodeBinding object, you must specify the criteria for binding. The criteria indicates when a data item should be bound to a node. You can specify the TreeNodeBinding.Depth or TreeNodeBinding.DataMember property, or both properties. There is a slight performance gain by specifying both. A node depth specifies the node level that gets bound. For example, the following System.Web.UI.WebControls.TreeNodeBinding declaration binds the Name and ID fields of the data source to the TreeNode.Text and TreeNode.Value properties, respectively, of all nodes with a depth of 0:
Example
<asp:TreeNodeBinding Depth="0" TextField="Name" ValueField="ID">
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. Each data item in a hierarchical data source (represented by a System.Web.UI.IHierarchyData interface) exposes a System.Web.UI.IHierarchyData.Type property, which specifies the type of the data item. For example, the data member for an XML element specifies the name of the element. When a data source contains multiple data item types, the data member specifies which data item type to use. The following System.Web.UI.WebControls.TreeNodeBinding declaration binds the <Book> elements of an System.Web.UI.WebControls.XmlDataSource control to all the nodes in the tree, regardless of the location in the hierarchy:
Example
<asp:TreeNodeBinding DataMember="Book" TextField="Title" ValueField= "ISBN">
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 bind to a field of a data item or to a static value. When bound to a static value, all System.Web.UI.WebControls.TreeNode objects to which the System.Web.UI.WebControls.TreeNodeBinding object is applied share the same value.
You can selectively override a bound property in a System.Web.UI.WebControls.TreeNode object by setting the corresponding property directly in the node.
The following table lists the properties of the System.Web.UI.WebControls.TreeNodeBinding class that allow you to bind a property of the System.Web.UI.WebControls.TreeNode object to a field of a data item.
TreeNodeBinding.ImageUrlField |
The field to bind to the TreeNode.ImageUrl property of a System.Web.UI.WebControls.TreeNode object. |
TreeNodeBinding.ImageToolTipField |
The field to bind to the TreeNode.ImageToolTip property of a System.Web.UI.WebControls.TreeNode object. |
TreeNodeBinding.NavigateUrlField |
The field to bind to the TreeNodeBinding.NavigateUrl property of a System.Web.UI.WebControls.TreeNode object. |
TreeNodeBinding.TextField |
The field to bind to the TreeNode.Text property of a System.Web.UI.WebControls.TreeNode object. |
TreeNodeBinding.ToolTipField |
The field to bind to the TreeNode.ToolTip property of a System.Web.UI.WebControls.TreeNode object. |
TreeNodeBinding.ValueField |
The field to bind to the TreeNode.Value property of a System.Web.UI.WebControls.TreeNode object. |
The following table lists the properties of the System.Web.UI.WebControls.TreeNodeBinding class that allow you to bind a property of the System.Web.UI.WebControls.TreeNode object to a static value.
If conflicting System.Web.UI.WebControls.TreeNodeBinding objects are defined, 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.]The System.Web.UI.WebControls.TreeNodeBinding class also allows you to format the text that is displayed in a node by setting the TreeNodeBinding.FormatString property.