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. Advertisements

  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. Advertisements

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:
    641
    George Ter-Saakov
    Jul 3, 2003
  2. Hazz

    hypothetical org chart solution

    Hazz, Dec 1, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    627
  3. Sahil Malik [MVP]

    Displaying an Org Chart

    Sahil Malik [MVP], Sep 26, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    872
    =?Utf-8?B?RG9uIEQ=?=
    Sep 27, 2005
  4. gnewsgroup
    Replies:
    4
    Views:
    3,282
    Kevin Spencer
    Feb 6, 2008
  5. Ben Smith

    Org Chart Component for ASP.NET

    Ben Smith, Dec 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    351
    Ben Smith
    Dec 26, 2003
  6. Tarek
    Replies:
    6
    Views:
    569
    Chris Hohmann
    Nov 19, 2004
  7. PerlFAQ Server
    Replies:
    0
    Views:
    1,017
    PerlFAQ Server
    Feb 3, 2011
  8. PerlFAQ Server
    Replies:
    0
    Views:
    993
    PerlFAQ Server
    Apr 4, 2011
Loading...