ぁwō'd溡緔*

.ㄧ┠愛.│是最後一次___". 傷.│也到此為止 _ ...ㄧ做個浪子..┻┕┅獨行天下!!

TreeView  tree_gameNews

 

DataSet ds=new DataSet();
            string parentComstr = "select ModelID,Model_Name from Model";
            string childComstr = "select ModuleID,Mod_Name,ModelID from Module";
            SqlConnection conn = new SqlConnection(user.connection());
            SqlCommand parentcom = new SqlCommand(parentComstr,conn);
            SqlCommand childcom = new SqlCommand(childComstr, conn);
            SqlDataAdapter parentda = new SqlDataAdapter(parentcom);
            SqlDataAdapter childda = new SqlDataAdapter(childcom);
            parentda.Fill(ds, "parent");
            childda.Fill(ds, "child");

            ds.Relations.Add(new DataRelation("kind", ds.Tables["parent"].Columns["ModelID"], ds.Tables["child"].Columns["ModelID"]));
            foreach (DataRow masterRow in ds.Tables["parent"].Rows)
            {
                TreeNode masterNode = new TreeNode();
                masterNode.Text = masterRow["Model_Name"].ToString();
                masterNode.NavigateUrl = "";
                masterNode.Target = "module";
                tree_gameNews.Nodes.Add(masterNode);
                foreach (DataRow childrow in masterRow.GetChildRows("kind"))
                {
                    TreeNode childnode = new TreeNode();
                    childnode.Text = childrow["Mod_Name"].ToString();
                    childnode.Target = "module";
                    childnode.NavigateUrl = "Column_body.aspx?moduleid=" + childrow["ModuleID"].ToString() ;
                    masterNode.ChildNodes.Add(childnode);    
                }
            }

posted on 2007-04-23 09:10  Top.Net  阅读(844)  评论(1编辑  收藏  举报