|
I'm attempting to create a user interface for a dynamic tree view menu.
My problem is that as I check for child menus if that child HAS children then I need to re-run my subroutine for that menu. Since I don't know the potential number of nested children it is impossible for me to determine the number of recordsets I would need.
I'm stumped on the best approach. Here is my best attempt so far. This code works great if I have no more than one level of nested children. This script is in its infancy so no true functionallity exists I'm just trying to figure out how to properly nest the data for display.
========================================
Sub WriteChildren(arrChildren)
Dim RowMax, ColMax, intRow
RowMax = UBound(arrChildren,2)
ColMax = UBound(arrChildren,1)
For intRow = 0 To RowMax
Response.Write "..." & arrChildren(1, intRow) & " "
Response.Write "<br>"
'CheckForChild(arrChildren(0,intRow)) 'This bombs the page if not commented
Next
End Sub
Sub CheckForChild(mParent)
Dim arrSubMenu
rsSubMenu.Filter = "mParent='" & rsMenu("Menu_ID") & "'"
If rsSubMenu.EOF Then
'No Children
rsSubMenu.Filter = adFilterNone
Else
arrSubMenu = rsSubMenu.GetRows()
rsSubMenu.Filter = adFilterNone
WriteChildren arrSubMenu
End If
End Sub
Dim rsMenu 'RS object for top level menu items
Dim rsSubMenu 'RS object for sublevel menu items
Set rsMenu = Server.CreateObject("ADODB.Recordset")
Set rsSubMenu = Server.CreateObject("ADODB.Recordset")
SetConnection 'Database subroutine in seperate file
'Open Top Level RS
strSQL = "SELECT Menu_ID, mDesc, mParent, mWidth, mHeight FROM tblMenu WHERE mParent IS NULL"
OpenRecordset rsMenu, strSQL, adOpenStatic, adLockReadOnly, adCmdText
'Open Sub Level RS
strSQL = "SELECT Menu_ID, mDesc, mParent, mWidth, mHeight FROM tblMenu WHERE mParent IS NOT NULL"
OpenRecordset rsSubMenu, strSQL, adOpenStatic, adLockReadOnly, adCmdText
If Not rsMenu.EOF Then
While Not rsMenu.EOF
Response.Write rsMenu("mDesc")
WriteLinks rsMenu("Menu_ID")
CheckForChild (rsMenu("Menu_ID"))
rsMenu.MoveNext
Wend
Else
Response.Write "No Menu Items Found In Database"
End If
'All below are database subroutines in separate file
CloseandKillRecordset(rsMenu)
CloseandKillRecordset(rsSubMenu)
CloseConnection
This produces the following output:
TOP LEVEL ITEM #1 ....1st CHILD TO #1 ....2nd CHILD TO #1 TOP LEVEL ITEM #2 TOP LEVEL ITEM #3 ....1st CHILD TO #3 ....2nd CHILD TO #3 TOP LEVEL ITEM #4
etc...etc...
|