Hey there,
What could you do is to run a SELECT statement like this:
SELECT * FROM [TableName]
After you got the query results into a DataTable Object, you should run a For each loop like this:
For each(DataRow dr in DataTable)
{
TreeNode trnode = new TreeNode();
if(dr["ParentCategory"].Value == 0)
{
trnode.text = dr["CategoryName"].Value.ToString();
trnode.Tag = dr["CategoryId"].value.toString();
TreeView.nodes.Add(trnode);
}
else
{
TreeNode parent = //Find the ParentNode from the Tag Property
trnode.text = dr["CategoryName"].Value.ToString();
trnode.Tag = dr["CategoryId"].value.toString();
parent.Add(trnode);
}
}
Note that in order for this to work you have to spesify that the nodes that don't have a parent( which means that they are parent nodes) have to have a unique number (like 0 or whatever you like).
Cheers.