index | search | no replies | posting guidelines | help login | register
Index » General » Site & Forum Feedback
search this forum:
:: ASP treeview question :: (2)Post a New Message | Post a Reply
Oct 18 2005, 8:12 AM
 ASP treeview questionPost a Reply
 ericb

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

since: Oct 18, 2005
from: DE

Hopefully this is the correct forum to post this message.  I'm trying to set up the asp treeview from a database, and I've got that working ok, but I'm trying to add one thing:  I want to filter the tree nodes based on the user.

I set up another table with usernames, etc., and an ID field that corresponds to the menuID of the treeview, so that for each node a user can view, they have a corresponding ID in another table.  But no matter how I try to set this up, it work work, or the tree is messed up.

Has this ever been done with this tree?  Any help or suggestions, or samples, is greatly appreciated, thanks!

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: