The
TreeView
control is a hierarchical data control. Child nodes need a reference to a parent node. So you should have a table that has the fields: Id & parentId. The child <> parent relationship is then
parentId = Id
So once you load your data into a
DataTable
, you can do something like this:
foreach (DataRow row in data.Rows)
{
TreeNode node = new TreeNode(dr["field1"], dr["fieldId"])
node.PopulateOnDemand = true;
TreeView1.Nodes.Add(node);
}
protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{
string fieldId = e.Node.Value;
foreach (DataRow row in topics.Rows)
{
TreeNode node = new TreeNode(dr["field1"], dr["fieldId"])
node.PopulateOnDemand = true;
e.Node.ChildNodes.Add(node);
}
}