treeview递归
public TreeNode fillnode(TreeNode tn)//递归
{
SqlConnection con = DB.creation();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select LID,RID from huiyuan where HyID='" + tn.Text + "'", con);
DataSet ds = new DataSet();
sda.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count>0)
{
if (!Convert.IsDBNull(ds.Tables[0].Rows[0]["lid"]))
{
TreeNode tnl = new TreeNode();
tnl.Text = ds.Tables[0].Rows[0]["lid"].ToString();
tnl = fillnode(tnl);
tn.ChildNodes.Add(tnl);
}
if (!Convert.IsDBNull(ds.Tables[0].Rows[0]["rid"]))
{
TreeNode tnr = new TreeNode();
tnr.Text = ds.Tables[0].Rows[0]["rid"].ToString();
tnr = fillnode(tnr);
tn.ChildNodes.Add(tnr);
}
}
return tn;
}
浙公网安备 33010602011771号