1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
| private void PopulateRootLevel() { SqlConnection objConn = new SqlConnection("Hier ist meine SQLDatenbankverbindung gesetzt"); SqlCommand objCommand = new SqlCommand("SELECT ID, isnull([Description1],'') + ' (' +isnull([Address4], '') + ', '+ isnull([City], '') +')' as Beschreibung, (Select Count(*) FROM [dbo].[tblCompanies] where [HoldingCompanyID] = t.ID ) AS childnodecount FROM [dbo].[tblCompanies] t WHERE Hierachy is null AND xxxHide = 0 AND HoldingCompanyID is not null", objConn); SqlDataAdapter da = new SqlDataAdapter(objCommand); DataTable dt = new DataTable(); da.Fill(dt);
PopulateNodes(dt, TreeView1.Nodes); }
private void PopulateNodes(DataTable dt, TreeNodeCollection nodes) { foreach (DataRow dr in dt.Rows) { TreeNode tn = new TreeNode(); tn.Text = dr["Beschreibung"].ToString(); tn.Value = dr["ID"].ToString(); nodes.Add(tn);
tn.PopulateOnDemand = (Convert.ToInt32(dr["childnodecount"]) > 0); } } private void PopulateSubLevel(int parentid, TreeNode parentNode) { SqlConnection objConn = new SqlConnection("Hier ist meine SQLDatenbankVerbindung gesetzt"); SqlCommand objCommand = new SqlCommand("SELECT ID, isnull([Description1],'') + ' (' +isnull([Address4], '') + ', '+ isnull([City], '') +')' as Beschreibung, (Select Count(*) FROM [dbo].[tblCompanies] where [HoldingCompanyID] = t.ID ) AS childnodecount FROM [dbo].[tblCompanies] t WHERE Hierachy is not null AND xxxHide = 0 AND HoldingCompanyID != 1 AND HoldingCompanyID is not null and HoldingCompanyID = @parentID", objConn); objCommand.Parameters.Add("@parentID", SqlDbType.Int).Value = parentid; SqlDataAdapter da = new SqlDataAdapter(objCommand); DataTable dt = new DataTable(); da.Fill(dt); PopulateNodes(dt, parentNode.ChildNodes); }
protected void TreeView1_TreeNodePopulate(object sender, System.Web.UI.WebControls.TreeNodeEventArgs e) { PopulateSubLevel(Convert.ToInt32(e.Node.Value), e.Node); } |