treeview怎么与access数据库实现绑定

2024-11-07 21:49:54
推荐回答(1个)
回答1:

递归方法。
//


/// TreeView数据绑定
///

///
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);
}
}
}