for stored procedure: http://dotnetacademy.blogspot.com/2011/05/get-all-child-nodes-of-parent-in-self.html
private void buildTree() { Listcml; cml = cmf.GetAll(); TVcategory.Nodes.Clear(); AddNodes(0, TVcategory.Nodes, cml); } void AddNodes(int id, TreeNodeCollection tn, List cml) { foreach (Categorymaster cm in cml.Where(s => s.Parentid == id)) { //TreeNode sub = new TreeNode("" + cm.Category_name + "", cm.Category_id.ToString()); TreeNode sub = createTree(cm); tn.Add(sub); AddNodes(Convert.ToInt32(sub.Value), sub.ChildNodes, cml); } } private TreeNode createTree(Categorymaster cm) { TreeNode tn = new TreeNode("" + cm.Category_name + "", cm.Category_id.ToString()); if (catid > 0) { if (cm.Category_id == catid) { tn.Selected = true; } } return tn; }
No comments:
Post a Comment