Using the TreeView control to create an Org Chart

Discussion in 'ASP .Net Web Controls' started by Rob Edwards, Dec 4, 2003.

  1. Rob Edwards

    Rob Edwards Guest

    I'm trying to use the TreeView web control to create an org chart from an
    Employee table.

    Table: Employee
    Fields:
    EmployeeID
    EmployeeLastName
    EmployeeFirstName
    ManagerID

    Where ManagerID is another record in the same Employee table.

    I would like to use the Treeview control to traverse down the org chart...
    using the relationshp between EmployeeID and ManagerID....

    Can someone help get me started on the right track?

    Thanks
    Rob Edwards, Dec 4, 2003
    #1
    1. Advertising

  2. Rob Edwards

    MSFT Guest

    Hi Rob,

    We may first fill a dataset wit the org table data, and add the nodes in
    treeview. Here is a smaple on this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    Dim root As New Microsoft.Web.UI.WebControls.TreeNode

    root.Text = "Org"

    TreeView1.Nodes.Add(root)

    SqlDataAdapter1.Fill(DataSet11)


    addsubnode(0, root)


    End Sub


    Private Sub addsubnode(ByVal managerID As Integer, ByRef parentnode As
    Microsoft.Web.UI.WebControls.TreeNode)


    Dim dr As DataRow
    Dim cnode As Microsoft.Web.UI.WebControls.TreeNode

    For Each dr In DataSet11.org.Rows

    If dr("ManagerID") = managerID Then
    cnode = New Microsoft.Web.UI.WebControls.TreeNode
    cnode.Text = dr("EmployeeFirstName") + " "
    +dr("EmployeelastName")
    parentnode.Nodes.Add(cnode)
    addsubnode(dr("EmployeeID"), cnode)
    End If
    Next

    End Sub
    MSFT, Dec 5, 2003
    #2
    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. Bob Wagner

    Re: Dynamic Org Chart

    Bob Wagner, Jul 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    565
    George Ter-Saakov
    Jul 3, 2003
  2. gnewsgroup
    Replies:
    4
    Views:
    2,989
    Kevin Spencer
    Feb 6, 2008
  3. Tarek
    Replies:
    6
    Views:
    305
    Chris Hohmann
    Nov 19, 2004
  4. PerlFAQ Server
    Replies:
    0
    Views:
    658
    PerlFAQ Server
    Feb 3, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    663
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page