using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; public partial class admin_news_range : MyWeb.config { DataTable treeDt = new DataTable(); const int LevelMax = MyWeb.news.KindLevelMax; //分類層數 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { TreeTopology(); BuildChild(0, TreeView2.Nodes); } } protected void TreeTopology() { MyWeb.sql sql = new MyWeb.sql(); OleDbConnection sqlConn = sql.conn(db, p_name); try { sqlConn.Open(); OleDbCommand sqlCmd = new OleDbCommand("", sqlConn); sqlCmd.CommandText = "SELECT num,kind,root FROM news_kind ORDER BY root, range"; treeDt = sql.dataTable(sqlCmd); } catch (Exception ex) { Response.Write(ex.Message); } finally { sqlConn.Close(); sqlConn.Dispose(); } } public void BuildChild(int RootUid, TreeNodeCollection Nodes, int Level=1) { DataTable dt = treeDt; foreach (DataRow row in dt.Rows) { if (row["root"].ToString() == RootUid.ToString()) { TreeNode NewNode = new TreeNode(); if (Convert.ToString(Request["num"]) == row["num"].ToString()) { NewNode.Text = "" + row["kind"].ToString() + ""; } else { NewNode.Text = row["kind"].ToString(); } NewNode.NavigateUrl = Request.Url.AbsolutePath + "?num=" + row["num"].ToString(); //NewNode.Target = "f_range"; NewNode.Expand(); Nodes.Add(NewNode); if (Level + 1<= LevelMax) { BuildChild((int)row["num"], NewNode.ChildNodes, Level + 1); } } } } }