I have a following List of data and I want display in Tree like fashion. I able to display the with two levels of subfolders (sequentially). But this issue is it can have any number of subfolders. Looks like recursive is the way to go but not sure how to proceed. Any help ?
Sample Data
ItemName ItemID NodeID ParentNodeID NodeName
0 100 null Node1
Item1 123 100 null
Item2 124 100 null
0 101 null Node2
Item3 125 101 null
Item4 126 101 null
0 103 101 Node3
Item5 127 103 null
0 104 103 Node4
Item6 128 104 null
0 105 null Node5
Item5 127 105 null
Expected Output
Node1
------Item1
------Item2
Node2
------Item3
------Item4
------Node3
--------Item5
--------Node4
------Item6
Node5
-------Item5
What I have tried
Loop through my data
If parentnodeid is null
find in the list object whether folder exists
if so append an item to it and add to the list
else create folder and add to the list
else
process sub folder
if itemid = 0
find in the list whether the folder exist
if so, append to the parent folder and add to the list
else
add the item to the list
end if