protected void BindTreeData()
{
OleDbConnection myConnection = new OleDbConnection(ConfigurationManager.AppSettings["ConnectionString_ms"]);
string selectCmd = "select fjd_dm ParentId ,jd_dm Id ,jd_mc text , gnmk_ljmc NavigateUrl from qx_gnmk_gnmb order by jd_order ";
DataSet dSet1 = new DataSet();
OleDbDataAdapter myCommand = new OleDbDataAdapter(selectCmd, myConnection);
myCommand.Fill(dSet1, "UserData");
dSet1.Relations.Add("TreeRelation", dSet1.Tables[0].Columns["Id"], dSet1.Tables[0].Columns["ParentId"]);
foreach (DataRow row in dSet1.Tables[0].Rows)
{
if (row.IsNull("ParentId"))
{
ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
node.Text = row["Text"].ToString();
node.Expanded = true;
treeMenu.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
private void ResolveSubTree(DataRow dataRow, ExtAspNet.TreeNode treeNode)
{
DataRow[] rows = dataRow.GetChildRows("TreeRelation");
if (rows.Length > 0)
{
treeNode.Expanded = true;
foreach (DataRow row in rows)
{
ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
node.Text = row["Text"].ToString();
node.NavigateUrl = row["NavigateUrl"].ToString();
treeNode.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
|