private void BindPaperCategoryTree() { PaperCategoryBLL paperCategoryBLL = new PaperCategoryBLL(); IList <RailExam.Model.PaperCategory> paperCategoryList = paperCategoryBLL.GetPaperCategories(); if (paperCategoryList.Count > 0) { TreeViewNode tvn = null; foreach (PaperCategory paperCategory in paperCategoryList) { tvn = new TreeViewNode(); tvn.ID = paperCategory.PaperCategoryId.ToString(); tvn.Value = paperCategory.PaperCategoryId.ToString(); tvn.Text = paperCategory.CategoryName; tvn.ToolTip = paperCategory.CategoryName; if (paperCategory.ParentId == 0) { TreeView1.Nodes.Add(tvn); } else { try { TreeView1.FindNodeById(paperCategory.ParentId.ToString()).Nodes.Add(tvn); } catch { TreeView1.Nodes.Clear(); SessionSet.PageMessage = "数据错误!"; return; } } } } TreeView1.DataBind(); TreeView1.ExpandAll(); }
private void BindTree() { KnowledgeBLL knowledgeBLL = new KnowledgeBLL(); IList <RailExam.Model.Knowledge> knowledgeList = knowledgeBLL.GetKnowledges(); if (knowledgeList.Count > 0) { TreeViewNode tvn = null; foreach (RailExam.Model.Knowledge knowledge in knowledgeList) { tvn = new TreeViewNode(); tvn.ID = knowledge.KnowledgeId.ToString(); tvn.Value = knowledge.IdPath.ToString(); tvn.Text = knowledge.KnowledgeName; tvn.ToolTip = knowledge.KnowledgeName; if (knowledge.ParentId == 0) { TreeView1.Nodes.Add(tvn); } else { try { TreeView1.FindNodeById(knowledge.ParentId.ToString()).Nodes.Add(tvn); } catch { TreeView1.Nodes.Clear(); SessionSet.PageMessage = "数据错误!"; return; } } } } TreeView1.DataBind(); //TreeView1.ExpandAll(); }