日期:2014-05-18  浏览次数:20511 次

csdn论坛左面列表怎么递归出来 的
各位给讲讲吧

------解决方案--------------------
他具体用什么实现的我就不知道拉!!!
但我做的一个开发和他的很类似...
下面的是我的一些代码,自己看看吧.... 


public SqlConnection GetCon()
{
SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
return myConn;
}
/// <summary>
/// 动态填充节点
/// </summary>
/// <param name="node">TreeView控件的节点</param>
public void ParentTree(TreeNode node)
{
DataSet ResultSet = RunQuery("Select parent_Id, title From tb_ParentTree ");
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
TreeNode NewNode = new TreeNode(row["title"].ToString(), row["parent_Id"].ToString());
NewNode.PopulateOnDemand = true;
NewNode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(NewNode);

}

}

}
/// <summary>
/// 动态填充节点
/// </summary>
/// <param name="node">TreeView控件的节点</param>
public void ChildTree(TreeNode node)
{
DataSet ResultSet = RunQuery("Select title From tb_ChildTree Where parent_Id=" + node.Value);
if (ResultSet.Tables.Count > 0)
{
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
TreeNode NewNode = new TreeNode(row["title"].ToString());
NewNode.PopulateOnDemand = false;
NewNode.SelectAction = TreeNodeSelectAction.None;
node.ChildNodes.Add(NewNode);

}

}

}

public DataSet RunQuery(String QueryString)
{
SqlConnection DBConnection = GetCon();
SqlDataAdapter DBAdapter;
DataSet ResultsDataSet = new DataSet();

try
{
DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
DBAdapter.Fill(ResultsDataSet);
DBConnection.Close();

}
catch (Exception ex)
{
if (DBConnection.State == ConnectionState.Open)
{
DBConnection.Close();
}

Message.Text = "Unable to connect to the database.";

}

return ResultsDataSet;

}
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
switch (e.Node.Depth)
{
case 0:
ParentTree(e.Node);
break;
case 1:
ChildTree(e.Node);
break;
default:
break;
}
}