asp.net.ph

Skip Navigation Links

Binding a TreeView Control to a Data Source

Controls You Can Use on Web Forms   ASP.NET Navigation Controls   TreeView Control


For sites that frequently add or change content, the site’s navigational structure can be better organized and maintained in a separate XML file. When bound to a TreeView control, any change made to the XML file automatically appears in the TreeView control. This ensures that updated content is always readily accessible to users of the Web site.

The TreeView control can be bound to the appropriate data source type, using any of the following ways:

  1. The TreeView control can use any hierarchical data source control, such as an XmlDataSource control or a SiteMapDataSource control.

    To bind to a hierarchical data source control, set the DataSourceID property of the TreeView control to the ID value of the data source control. The TreeView control automatically binds to the specified data source control. This is the preferred method to bind to data.

  2. The TreeView control can also be bound to an XmlDocument object.

    To bind to this data source, set the DataSource property of the TreeView control to the data source and then call the DataBind method.

The following example demonstrates how to use declarative syntax to create a TreeView control bound to a SiteMapDataSource.

<asp:treeview id="myTreeView" runat="server"
   datasourceid="siteMap"
   expanddepth=1 />

<asp:sitemapdatasource id="siteMap" runat="server" />

 Show me 

See Also

Customizing the TreeView Control User Interface   Responding to TreeView Item Events



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note