protected void CreateTreeView()
{
TreeNode rootNode = new TreeNode();
rootNode.Text = "全部";
rootNode.Value = "-1";
BasicTypeTreeView.Nodes.Add(rootNode);
BasicInformationManager BasicManager = new BasicInformationManager();
var tlist = BasicManager.GetAllBasicInfoTypes();
foreach (Model.BasicInforType mtype in tlist)
{
if (mtype.ParentID == 0)
{
TreeNode Node = new TreeNode();
//添加根节点
Node.Text = mtype.BasicTypeName;
Node.Value = mtype.ID.ToString();
Node.ToolTip = "编码" + mtype.BasicCode;
getSubNode(ref Node, mtype.ID);
rootNode.ChildNodes.Add(Node);
}
}
}
/// <summary>
/// 获取treeView子节点
/// </summary>
/// <param name="node"></param>
/// <param name="item"></param>
public void getSubNode(ref TreeNode node, int item)
{
BasicInformationManager BasicManager = new BasicInformationManager();
var tlist = BasicManager.GetBasicInforTypeByParentId(item);
if (tlist.Count > 0)
{
foreach (Model.BasicInforType m in tlist)
{
TreeNode subNode = new TreeNode();
subNode.Text = m.BasicTypeName;
subNode.Value = m.ID.ToString();
subNode.ToolTip = "编码" + m.BasicCode;
getSubNode(ref subNode, m.ID);
node.ChildNodes.Add(subNode); //进行子节点循环添加
}
}
}