You could sort list by ManagerID, presumed that people that don't have manager have ManagerID = 0 because is Important that "Top" managers would be added first, and just start to add from top and search for the parent, if there is no parent then person is "Top" manager with no managers for him and add it to the root of the treeview.
Something like this :
protected void Page_Load(object sender, EventArgs e)
{
List<People> pplList = LoadPeople();
foreach (People person in pplList.OrderBy(pp => pp.ManagerID))
{
IEnumerable<TreeNode> nodes = Extensions.GetItems<TreeNode>(TreeViewPeople.Nodes, item => item.ChildNodes);
TreeNode parent = nodes.FirstOrDefault(nn => nn.Value.Equals(person.ManagerID.ToString()));
TreeNode newNode = new TreeNode(person.Name, person.ID.ToString());
if (parent == null)
TreeViewPeople.Nodes.Add(newNode);
else
parent.ChildNodes.Add(newNode);
}
}
and here is the GetItems method that will return all tree nodes, taken from here : https://stackoverflow.com/a/1815600/351383
public static class Extensions
{
public static IEnumerable<T> GetItems<T>(this IEnumerable collection, Func<T, IEnumerable> selector)
{
Stack<IEnumerable<T>> stack = new Stack<IEnumerable<T>>();
stack.Push(collection.OfType<T>());
while (stack.Count > 0)
{
IEnumerable<T> items = stack.Pop();
foreach (var item in items)
{
yield return item;
IEnumerable<T> children = selector(item).OfType<T>();
stack.Push(children);
}
}
}
}