TreeView can be bound with XmlDataSource and SiteMapDataSource controls (vs2008exp). But the data come up from the database, a strongly typed DataSet. So, manually populate a TreeView from a DataTable object, instead of auto binding:

int currYear = 0;
TreeNode curRootNode = new TreeNode();
int i = 0;

do
{
rw = dt.Rows[i];
if (rw.theYear != currYear)
{
currYear = rw.theYear;
TreeNode root = new TreeNode(currYear);
curRootNode = root;
this.TreeView1.Nodes.Add(root);
TreeNode child = new       TreeNode(Enum.GetName(typeof(ShortMonthName),rw.theMonth) + “. [" +       rw.itemNumber + "]“);
curRootNode.ChildNodes.Add(child);
}
else
{
TreeNode child = new TreeNode(Enum.GetName(typeof(ShortMonthName), rw.theMonth) + “. [" + rw.itemNumber + "]“);
curRootNode.ChildNodes.Add(child);
}
i++;
} while (i < dt.Rows.Count);

Here is the result:

archiveTreeView

Leave a Reply