index | search | no replies | posting guidelines | help login | register
Index » General » Site & Forum Feedback
search this forum:
:: ASP treeview question ::    show all messagesPost a New Message | Post a Reply
Oct 19 2005, 9:30 AM
 Re: ASP treeview questionPost a Reply
 whichman

View this author's profile Send this author a private message Visit author's homepage

from: Laurel, MD

If you want to filter the nodes returned from the database depending on the user who is logged in, all you have to do is add a filter to your SQL statement. in the LoadFromDB procedure.

For example if you wanted to filter by a UserGroup field in you Menu table then the code might look like that below;


'load the treeview from the 'Menu' database table filtered by the UserGroup field
Call objTV.LoadFromDB(strConn,"Menu","UserGroup=" & Session("UserGroup"))




Public  Sub LoadFromDB(strConn, strMenuTable,  strCondition)
      Dim Conn  
      Set Conn = Server.CreateObject("ADODB.Connection")
     Conn.Open strConn
           
      Dim SQL, RS, node, parentid, parentNode
     SQL = "SELECT * FROM "& strMenuTable
      If strCondition <> "" Then
          SQL = SQL & " WHERE "& strCondition
      End  If
     SQL = SQL & " ORDER BY MenuID, ParentID"
      
      Set RS = Conn.Execute(SQL)
           
      If Not RS.EOF  Then
           Do  While Not RS.EOF
               parentid=RS("ParentID")
                     
                Dim child                     
                Set child =  New Node
                Call child.Init(RS("Text"), RS("URL"), RS("ToolTip"))
               child.ID =RS("MenuID")
                     
                If parentid=0  Then
                    Nodes.Add(child)
                Else
                     Set parentNode = FindNode(Nodes, ParentID)
                     If Not (parentNode Is  Nothing)  Then
                         parentNode.Add(child)
                     End  If
                End  If
               RS.MoveNext           
           Loop
          RS.Close
      End  If
      Set RS =  Nothing
     Conn.Close  
      Set Conn = Nothing           
  End  Sub





-------------------------
Master of the Game
Pages: (1)   [1]

search this forum: