The application is currently developed using ASP.NET (C#)
I have code to pull data from a SQL Server 2008 table and organize it into an hierarchy:
With hierarchy (id, [location id], name, depth, trail)
-- selects the "root" level items.
Select ID, [LocationID], Name, 1 As depth, [trail] = cast(Name + '/' as varchar(255))
Where ID = [LocationID]
-- selects the descendant items.
Select child.id, child.[LocationID], child.name,
parent.depth + 1 As depth, [trail] = cast(trail + child.name + '/' as varchar(255))
From dbo.Locations As child
Inner Join hierarchy As parent
On child.[LocationID] = parent.ID
Where child.ID != parent.[Location ID])
-- invokes the above expression.
Order By depth
In the "trail" column each field will display the hierarchy separated by a '/'.
I would like to display these "paths" as a tree view.
Is there a more efficient way to do this, rather than just parse the "trail" column from my SQL table. Could I do it with C# while initially building the hierarchy?
Any help is appreciated.