您的位置:首页 > 其它

使用递归的方法生产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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: