Using the TreeView control to create an Org Chart

R

Rob Edwards

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
 
M

MSFT

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top