What is the best way to generate a hierarchical treeview in asp.net (C#) from a SQL database table filled with all of a company's employees? I will never know at what level or employee I will be starting at. Any links or directions would be appreciated.
Option one: Get hierarchical data from database in xml form (with FOR XML statement of SQL Server 2005 and newer) then whether deserialize it into business entity object or use in UI directly as datasource (treeview controls support XML data sources). With SQL Server 2008 you could also use HIERARCHYID field instead of ParentID, which simplifies things related to hierarchical data storing and retrieving, with it SELECT statement which retrieves data from a specified node will be much simplier.
Check out the Modified Preorder Tree Traversal technique at:
http://www.sitepoint.com/article/hierarchical-data-database/ http://en.wikipedia.org/wiki/Tree_traversal http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=1266295 http://iamcam.wordpress.com/2006/03/17/storing-hierarchical-data-in-a-database-part-1/