Treeview WebThe server control can display various types of data: static data specified by the control in the declaration mode; Data bound to the control; or dynamically added to the control in response to user operationsTreeviewControls.
1. Display static data
The simplest data architecture is declarative static data. To use declarative syntax to display static data, createTreeviewSet of child nodes of the control.
The following example shows how to displayTreeviewControl.
<Asp: Treeview id = "treeview1" runat = "server">
<Nodes>
<Asp: treenode value = "parent1" expanded = "true" text = "1">
<Asp: treenode value = "child1a" text = "A"/>
<Asp: treenode value = "child1b" text = "B"/>
</ASP: treenode>
<Asp: treenode value = "parent2" text = "2">
</ASP: treenode>
<Asp: treenode value = "parent3" expanded = "true" text = "3">
<Asp: treenode value = "child3a" text = "A">
</ASP: treenode>
</ASP: treenode>
</Nodes>
</ASP: Treeview>
2. bind to the data source
To display the data bound to the control as declared, first add a hierarchical data source control to the page (such Xmldatasource Control), and assign ID . Then Treeview Control Performanceid Property is set to ID . Treeview Control to automatically bind to the data source and display the value of the data source.
Note: Treeview Controls can be bound to implementations Ihierarchicaldatasource Any data source control of the interface, such Sitemapdatasource Object or Xmldatasource Object.
By default, when a data source is bound, if each data item of the data source contains multiple attributes (such XML Element has multiple attributes), the node displays Tostring Value returned by the method. Just XML The node displays the element name. This architecture shows the basic structure of the tree, but it is not very useful in other aspects. You can use Databindings The Set specifies the tree node to bind to the node to a specific data item attribute. Databindings Set that contains the relationship between the defined data item and the node to which it is bound Treenodebinding Object. You can specify the binding conditions and attributes of the data items to be displayed on the node.
Note: In addition, Treeview The control also provides Datasource Attribute and Databind Method.
3. dynamically display data
The data structure may not be defined statically, or the data may depend on the information collected during the runtime. On the server sideCodeProgram Treenode Object filling Treeview Control Nodes Collection, you can also use Treeview Control Populateondemand Function dynamically fills nodes when the parent node on the client is expanded.