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:
Code:With hierarchy (id, [location id], name, depth, trail) As ( -- selects the "root" level items. Select ID, [LocationID], Name, 1 As depth, [trail] = cast(Name + '/' as varchar(255)) From dbo.Locations Where ID = [LocationID] Union All -- 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. Select * From hierarchy Order By depth
In the "trail" column each field will display the hierarchy separated by a '/'.
Example:
TRAIL
_______________
Parent1/Child1/
Parent1/Child2/
Parent1/Child3/
Parent1/Child4/GrandChild1/
--
I would like to display these "paths" as a tree view.
Example:
HTML Code:+ Parent1 - Child1 - Child2 - Child3 - Child4 - GrandChild1
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.
Thanks.


Reply With Quote
