Assembly: System.Web (in system.web.dll)
The TreeNodeBindingCollection class is used to store and manage a collection of TreeNodeBinding objects in the TreeView control. The TreeView control uses the TreeNodeBindingCollection class for its DataBindings property.
The DataBindings property contains 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. Although the DataBindings collection can be programmatically populated, it is usually set declaratively.
To set the tree node bindings declaratively:
Nest opening and closing <DataBindings> tags between the opening and closing tags of the TreeView control.
Place <asp:TreeNodeBinding> elements between the opening and closing <DataBindings> tags for each tree node binding that you want to specify.
You can programmatically manage a TreeNodeBindingCollection by adding and removing TreeNodeBinding objects. To add a TreeNodeBinding object to the collection, use the Add or Insert method. To remove nodes from the collection, use the Remove, RemoveAt, or StateManagedCollection.Clear method.
The TreeNodeBindingCollection class supports several ways to access the items in the collection:
This section contains two code examples. The first code example demonstrates how to populate a TreeNodeBindingCollection object declaratively. The second code example demonstrates how to populate a TreeNodeBindingCollection object programmatically.
The following code example demonstrates how to populate a TreeNodeBindingCollection object declaratively. For this example to work correctly, you must copy the XML data that is located at the end of this section to a file called Book.xml.
The following code example demonstrates how to populate a TreeNodeBindingCollection object programmatically. For this example to work correctly, you must copy the sample XML data that is located at the end of this section to a file called Book.xml.
The following is the XML data for the preceding code examples.
<Book Title="Book Title"> <Chapter Heading="Chapter 1"> <Section Heading="Section 1"> </Section> <Section Heading="Section 2"> </Section> </Chapter> <Chapter Heading="Chapter 2"> <Section Heading="Section 1"> </Section> </Chapter> </Book>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.