You can represent a self-related data model with WebHierarchicalDataSource™. If your data entity contains fields that relate to each other, you can show the self-related data model as a hierarchical view using WebHierarchicalDataSource.
For example, the Employees table of the Northwind data base contains a ReportTo field that specifies the employee id that an employee reports to. You can display the hierarchy of employee order by defining a self-related relationship using WebHierarchicalDataSource.
You will display the Employees table in a hierarchical fashion in order to show who the employees report to. You will do this using a self-related data relation using the WebHierarchicalDataSource component. The hierarchy of data is displayed in a TreeView control.
Create an ASP.NET Webpage.
Drag a ScriptManager component on the form.
Drag a TreeView control on the form.
Drag a WebHierarchicalDataSource component on the form.
Drag a SqlDataSource component on the form.
Configure the SqlDataSource component to connect to the Employees table of the Northwind data base. Retrieve the EmployeeID, LastName, and ReportTo fields.
In the Quick Designer for WebHierarchicalDataSource, click Add View.
Select SqlDataSource1 as the data source.
Click Add Child to add the child data.
Select the same data source, SqlDataSource1, as the child data source.
In the Specify Fields to Join section, leave the EmployeeID field as the parent column and select the ReportsTo field as the child column.
Click Ok. You return to the Quick Design main screen.
Click Apply then OK. WebHierarchicalDataSource is now configured to display the SQL data as a hierarchy.
Click the Smart Tag for the TreeView control.
Select WebHierarchicalDataSource for the data source.
Click on the Edit TreeNode Databindings link. The TreeView DataBindings Editor appears.
Select SqlDataSource1_DefaultView in the Available data bindings section and click Add.
In the properties window, make sure SqlDataSource1_DefaultView is the DataMember and that the TextField property is set to LastName.
Click Apply then OK.
Run the application. You will see a hierarchical tree view that displays employee names nested according to the order of who they report to.