For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > October 2008 > TREEVIEW Help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author TREEVIEW Help
hodgesp

2008-10-17, 8:37 am

I have a question that I could use some help on.
I'm new to the 3.5 version of Visual studio and I'm creating my first project with it.

What I'm trying to do is create a TreeView that is populated from a couple of Sql Objects, one is a view, the other is a table.

What is happening is I can get the parent node to populate but when I try to add the child node the parent nodes just replicate. I know I'm close but what am I missing?

here is my code Snippet:


code:
//create a dataset object DataSet ds = new DataSet(); String sqlString = "Select descr, abbrev, orglvl, active, recid From dbo.organizationlist Order By 2"; String sqlString2 = "Select a.recid as deptid, a.descr as descr1, a.abbrev, a.orglvl, a.active ,b.[contact id] as cid ,rtrim(b.fname) + ' ' + IsNull(RTrim(b.mint),'') + ' ' + rtrim(b.sirname) as Contact ,b.fname,isnull(mint,''),b.mint,b.sirname From dbo.organizationlist a join dbo.vw_Contacts_by_OrgList b On a.recid = b.[dept id] order by 3"; //create an dataadapter SqlDataAdapter da = new SqlDataAdapter(sqlString.ToString(), sqlDS.ConnectionString.ToString()); //fill the dataset through the adapter da.Fill(ds, "organizationlist"); //create an dataadapter1 SqlDataAdapter da1 = new SqlDataAdapter(sqlString2.ToString(), sqlDS.ConnectionString.ToString()); //fill the dataset through the adapter da1.Fill(ds, "contacts"); ds.Relations.Add("OrgToContacts",ds.Tables["organizationlist"].Columns["recid"], ds.Tables["contacts"].Columns["deptid"]); //foreach loop(s) foreach (DataRow dr in ds.Tables ["organizationlist"].Rows) { TreeNode tn = new TreeNode(); //DataRow dr = new DataRow(); //nodeSupp = new TreeNode(); //nodeSupp.Text = rowSupp("CompanyName"); tn.Text = dr["descr"].ToString(); tn.Value = dr["recid"].ToString(); //.ID = rowSupp("SupplierID"); //TreeView1.Nodes.Add(nodeSupp); this.TreeView5.Nodes.Add(tn); foreach (DataRow cr in dr.GetChildRows("OrgToContacts")) //"contacts"].Rows) { TreeNode cn = new TreeNode(); cn.Text = cr["descr1"].ToString(); cn.Value = cr["cid"].ToString(); tn.ChildNodes.Add(cn); } } //clean up ds.Dispose(); da.Dispose(); da1.Dispose(); sqlDS.Dispose();
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com