使用递归的方法生产TreeView
2012-01-04 13:09
316 查看
public void ParentNode() //创建父节点
{
string sql;
if (p == "999999")
{
sql = "select id,LBMC from WJLBB where parent_id=0";
}
else
{
sql = "select id,LBMC from WJLBB where parent_id=0 and bmbh='" + bmbh + "'";
}
DataSet ds = newdbclient.DataSets(sql);
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = ds.Tables[0].Rows[i]["LBMC"].ToString();
tn.Value = ds.Tables[0].Rows[i]["id"].ToString();
TreeView1.Nodes.Add(tn);
ChildNode(tn, tn.Value);
//this.treeView1.Nodes.Add("onclick", "CheckEvent()");
}
}
}
public void ChildNode(TreeNode node, string fdeptid) //递归取出父节点下的子节点
{
string sql = "select id,LBMC from WJLBB where kf='开放' and parent_id='" + fdeptid + "'";
DataSet ds = newdbclient.DataSets(sql);
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = ds.Tables[0].Rows[i]["LBMC"].ToString();
tn.Value = ds.Tables[0].Rows[i]["id"].ToString();
node.ChildNodes.Add(tn);
//UserNode(tn, tn.Value); //在子节点下创建人员节点
ChildNode(tn, tn.Value);
}
}
}
{
string sql;
if (p == "999999")
{
sql = "select id,LBMC from WJLBB where parent_id=0";
}
else
{
sql = "select id,LBMC from WJLBB where parent_id=0 and bmbh='" + bmbh + "'";
}
DataSet ds = newdbclient.DataSets(sql);
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = ds.Tables[0].Rows[i]["LBMC"].ToString();
tn.Value = ds.Tables[0].Rows[i]["id"].ToString();
TreeView1.Nodes.Add(tn);
ChildNode(tn, tn.Value);
//this.treeView1.Nodes.Add("onclick", "CheckEvent()");
}
}
}
public void ChildNode(TreeNode node, string fdeptid) //递归取出父节点下的子节点
{
string sql = "select id,LBMC from WJLBB where kf='开放' and parent_id='" + fdeptid + "'";
DataSet ds = newdbclient.DataSets(sql);
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = ds.Tables[0].Rows[i]["LBMC"].ToString();
tn.Value = ds.Tables[0].Rows[i]["id"].ToString();
node.ChildNodes.Add(tn);
//UserNode(tn, tn.Value); //在子节点下创建人员节点
ChildNode(tn, tn.Value);
}
}
}
相关文章推荐
- 《转》---使用递归方法DataTable 绑定 TreeView
- 使用递归方法为TreeView添加数据
- 使用递归方法为TreeView添加数据
- 使用asp.net递归的方法来实现treeview的数据绑定
- 使用递归方法获得TreeView中CheckBox选中的节点
- 使用递归方法为TreeView添加数据
- 使用递归方法实现数字反转 C语言实现
- 手动绑定TreeView,使用递归,绝对能用的例子
- vuejs使用递归组件实现树形目录的方法
- 数据库绑定TreeView,使用递归
- 使用go和python递归删除.ds store文件的方法
- C#中TreeView组件使用方法初步
- C++使用递归方法求n阶勒让德多项式完整实例
- C#中TreeView组件使用方法初步
- 使用递归的方法计算1到100的叠加,即1+2+3+4.....+100
- 生产环境使用elasticsearch遇到的一些问题以及解决方法(不断更新)
- 黑马程序员--Java基础加强--15.利用反射操作泛型IV【通过反射Method解析泛型方法思路】【通过Method对四种Type子接口类型进行解剖】【使用递归对任意复合泛型类型进行彻底解剖】【个人
- jquery递归遍历xml文件,形成ul-li序列,生成树结构(使用了treeview插件)
- 关于treeView1_AfterSelect方法中节点的使用(代码介绍)
- 程序设计风格、几个控件、递归在TreeView中的使用