日期:2014-05-17 浏览次数:20598 次
DataSet data = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //data = 数据; SqlConnection conn = new SqlConnection("server=(local);uid=sa;pwd=;database=pubs"); SqlDataAdapter da = new SqlDataAdapter("select * from parent_channel ", conn); conn.Open(); da.Fill(data); InitTree(TreeView1.Nodes, "0"); } } public void InitTree(TreeNodeCollection Nds, string parentID) { TreeNode newNode; DataRow[] rows = data.Tables[0].Select("parentid=" + parentID); foreach (DataRow row in rows) { newNode = new TreeNode( row["title"].ToString(), row["lid"].ToString(), row["lid"].ToString()); Nds.Add(newNode); InitTree(newNode.ChildNodes, row["lid"].ToString()); } } /* 表结构 lid parentid title -------------------------- lid= 你的 id parnetid = 你的 fid title =你的 channelname */