Binding to Database Data

You cannot bind a TreeView control directly to a SqlDataSource or ObjectDataSource control because neither of these two controls exposes hierarchical data. If you want to display database data with the TreeView control, you have a choice: create a custom SqlHierarchicalDataSource control or programmatically bind the TreeView to the database data.

The hard option is to build a SQL hierarchical DataSource control. You can do this by deriving a new control from the base HierarchicalDataSourceControl class or by implementing the IHierarchicalDataSource interface. We explore this option in the final section.

The second option is to build the TreeView control programmatically from a set of database records. This is the approach ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.