Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Query for .net navigation menu / treeview

Hi Everyone,

I'm drawing a blank here and I am hoping someone can point me in the right direction. I have a table with the following columns (some omitted)

ID
GUID
PageName
ParentPageID

I want to build a hierarchical navigation system (2-tier). The conceptual problem that I am running into was getting this information from the same table. Initially I was going to use a nested repeater but I am thinking a treeview would be better. Anyway, the problem is the query. How would I start with something like this? Let's use the following as an example

Rows
(ID '1', GUID '888...', PageName 'Page A', ParentPageID '-1')
(ID '2', GUID '111...', PageName 'Page B', ParentPageID '-1')
(ID '3', GUID '222...', PageName 'Page C', ParentPageID '-1')
(ID '4', GUID '375...', PageName 'Page 1', ParentPageID '1')
(ID '5', GUID '562...', PageName 'Page 2', ParentPageID '1')
(ID '6', GUID '874...', PageName 'Page 3', ParentPageID '2')
(ID '7', GUID '388...', PageName 'Page 4', ParentPageID '3')


So, I want to be able to build a query so that I can do the following

Page A
Page 1
Page 2
Page B
Page 3
Page C
Page 4



Any help would be greatly appreciated. Thanks!
[1601 byte] By [goodfella] at [2007-11-11 10:31:49]
# 1 Re: Query for .net navigation menu / treeview
your problem can be solved by directly getting the data from database as XML and bind the XML to treeview or menu.
I have done using FOR XML EXPLICIT in query..
Try using this article
http://www.eggheadcafe.com/articles/20030804.asp
sumyy at 2007-11-11 23:43:22 >