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);
}
}