无限极分类装入Treeview
Declare @Id Int
Set @Id = 0;
---在此修改父节点
With RootNodeCTE(NodeId,ParentId,[text],orderid)
As
(
Select NodeId,ParentId,[text],orderid From S_Tree Where ParentId In (@Id)
Union All
Select S_Tree.NodeId,S_Tree.ParentId,S_Tree.[text],s_tree.orderid From RootNodeCTE
Inner Join S_Tree
On RootNodeCTE.NodeId = S_Tree.ParentId
)
Select * From RootNodeCTE order by ParentId,NODEID asc
【无限极分类装入Treeview】private void btnTreeView_Click(object sender, EventArgs e)
{
string xmlFile = @"E:\XML_F.xml";
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
DataTable dt = ds.Tables[0];
DataRow[] drss = dt.Select("ParentId = '38'");
string parentId = "0";
TreeNode treeNodeParent = new TreeNode("DataItems");
treeView1.Nodes.Add(treeNodeParent);
GenerateTree(parentId, dt, treeNodeParent);
treeView1.ExpandAll();
}
///
///
///
private void GenerateTree(string parentId, DataTable dt, TreeNode treeNodeParent)
{
string strWhere = " ParentId = '" + parentId + "'";
DataRow[] drs = dt.Select(strWhere);
if (drs.Length > 0)
{
foreach (DataRow dr in drs)
{
parentId =dr[0].ToString();
TreeNode treeNode = new TreeNode();
treeNode.Tag = dr[0].ToString();
treeNode.Text = dr[2].ToString() + "[" + dr[0].ToString() + "]";
treeNodeParent.Nodes.Add(treeNode);
GenerateTree(parentId, dt, treeNode);
}
}
}
推荐阅读
- 考研英语阅读终极解决方案——阅读理解如何巧拿高分
- 子龙老师语录
- 一些小日子
- 周一(十一)
- jQuery插件
- 07/22【晨读感悟】保持好奇心,生活才有无限可能
- 百度云极速下载,来体验飞的感觉,还可以看最新动漫的百度云视频哦
- 《通往财富自由之路》人生的终极问题到底是什么()
- 极简主义|极简主义 简记
- 星际无限|星际无限 | 官方推出Filecoin MinerX奖学金计划,吸引中小型Filecoin矿工