Displaying Preorder Tree Traversal Hierarchy in ASP?

Discussion in 'ASP General' started by FrankEBailey, Feb 13, 2006.

  1. FrankEBailey

    FrankEBailey Guest

    I've been reading up on Modified Preorder Tree Traversal and it's
    definitely ideal for the kind of tree structures I need to model for my
    company's multi-level sales hierarchy. I've implemented the database
    side already in SQL Server 2000 and can retrieve all child nodes based
    on the left and right IDs of the current node. My problem is displaying
    the tree so that correct indentation can be used to show the
    relationships between the parents and their respective child nodes.

    I'm aiming for this type of display:

    Organic_Produce
    - Fruit
    - Banana
    - Cherry
    - Orange
    - Vegetables
    - Potatoes
    - Savoury Potatoes
    - Sweet Potatoes
    - Zucchini

    etc.

    Now, I know a recursive function of some sort is needed, and I read on
    this page http://www.sitepoint.com/print/hierarchical-data-database how
    to create the function in PHP, however I don't have the first clue how
    to translate this into VBScript for implementation in ASP. If anyone
    has perhaps an example of how a function to display MPTT-type
    hierarchical data via VBScript, I will greatly appreciate any
    assistance you might be able to offer.

    Thanks in advance!
    Frank
     
    FrankEBailey, Feb 13, 2006
    #1
    1. Advertising

  2. FrankEBailey

    FrankEBailey Guest

    Can anyone help me on this?
     
    FrankEBailey, Feb 14, 2006
    #2
    1. Advertising

  3. >I've been reading up on Modified Preorder Tree Traversal and it's
    >definitely ideal for the kind of tree structures

    <snip>
    >Now, I know a recursive function of some sort is needed


    Actually I think the whole point of the left right values in this technique
    is to avoid having recursive functions which can become very slow.

    All you need is a single recordset ordered by Left. The code is something
    like this:-

    Dim lLastLeft
    Dim lDepth
    Dim alRight

    lDepth = 0

    lLastLeft = rs("left")

    ReDim alRight(4)
    alRight(lDepth) = rs("right")

    RenderRecord rs, lDepth
    rs.MoveNext

    Do Until rs.EOF

    Do Until alRight(lDepth) > rs("left")
    lDepth = lDepth - 1
    Loop

    If lDepth = UBound(alDepth) Then ReDim Preserve alRight(lDepth * 2)
    lDepth = lDepth + 1
    alRight(lDepth) = rs("right")

    RenderRecord rs, lDepth

    rs.MoveNext
    Loop

    Anthony.
     
    Anthony Jones, Feb 18, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Méndez
    Replies:
    9
    Views:
    500
    Dave Vandervies
    Nov 16, 2004
  2. ebrian
    Replies:
    0
    Views:
    330
    ebrian
    Feb 20, 2007
  3. David Méndez
    Replies:
    10
    Views:
    572
    Dave Vandervies
    Nov 16, 2004
  4. Replies:
    9
    Views:
    4,906
  5. Mark Space

    Tree Traversal

    Mark Space, Aug 24, 2007, in forum: Java
    Replies:
    1
    Views:
    930
    Jeff Higgins
    Aug 25, 2007
Loading...

Share This Page