I have a table in sql: table data goes like:
catid parentid catname
----- -------- -------------------
1 0 Operating Systems
2 1 Windows
3 1 Linux
4 5 Windows Server 2008
5 2 Windows Server
6 1 Unix
Parent id keeps its parent. For example; Windows Server 2008 comes first and belongs to Windows Server (its parent sometimes comes later).
In C#
side i got that table in dataset, but could not solve rest.
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
TreeNode root = new TreeNode();
TreeNode child = new TreeNode();
if (ds.Tables[0].Rows[i]["parentid"] == 0)
{
root.Text = ds.Tables[0].Rows[i]["catname"];
trview.Nodes.Add(root);
}
else
{
child.Text = ds.Tables[0].Rows[i]["catname"];
root.ChildNodes.Add(child);
}
}
How can i fill Treeview
according to table. I could not solve how to design loop for it. If parentid is belong to a catid, it will be node of it.
Thank you for any advise or help
Kind Regards
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…