ASP. NET-fill Tree nodes in the Treeview Web Server Control

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.