private void CompletaAlbero(TreeNodeCollection nodes, Business.Entity.Guida guida)
        {
            var voce = Business.Entity.Guida.GetItem(Business.Entity.Guida.KeyColumnsEnum.Id, guida.Id);
            TreeNode node = new TreeNode(voce.Titolo, voce.Id.ToString());
            if (NodiEspansi.Contains(voce.Id)) node.ExpandAll();

            foreach (var item in GuidaCollection.GetList(wherePredicate: "IdPrec == @0", whereValues: new object[] { voce.Id }, orderPredicate: "Posizione ASC")) CompletaAlbero(node.ChildNodes, item);
            nodes.Add(node);
        }
        private TreeNodeCollection GetChildNode(string RootNode, string[] valueArray, List<SPListItem> objListItemColn)
        {
            TreeNodeCollection childtreenodes = new TreeNodeCollection();
            SPQuery objSPQuery;
            SPListItemCollection objItems = null;
            List<SPListItem> objNodeListItems = new List<SPListItem>();
            SiteMapNodeCollection objNode = new SiteMapNodeCollection();
            objSPQuery = new SPQuery();
            string objNodeTitle = string.Empty;
            string objLookupColumn = string.Empty;
            StringBuilder Query = new StringBuilder();
            SPList objTaskList;
            SPField spField;
            string objKeyColumn;

            try
            {
                objTaskList = SPContext.Current.Web.Lists[objTreeViewControlField.ListName];
                objLookupColumn = objTreeViewControlField.ParentLookup;

                spField = SPContext.Current.Web.Lists[objTreeViewControlField.ListName].Fields[objTreeViewControlField.ParentLookup];
                if (this.ControlMode == SPControlMode.Display)
                {
                    objNodeListItems = (from SPListItem Item in objListItemColn
                                        where (new SPFieldLookupValue(Convert.ToString(Item[objTreeViewControlField.ParentLookup])).LookupValue == RootNode)
                                        orderby Item.ID
                                        select Item).ToList();

                }
                else
                {
                    Query.Append(String.Format(GlobalConstants.DYNAMIC_CAML_QUERY_GET_CHILD_NODE, spField.InternalName, RootNode));
                    objSPQuery.Query = Query.ToString();


                    objItems = objTaskList.GetItems(objSPQuery);
                    foreach (SPListItem objItem in objItems)
                    {
                        objNodeListItems.Add(objItem);
                    }

                }
                if (objNodeListItems != null && objNodeListItems.Count > 0)
                {
                    foreach (SPListItem objItem in objNodeListItems)
                    {
                        RootNode = Convert.ToString(objItem[GlobalConstants.LIST_COLUMN_TITLE]);
                        objKeyColumn = Convert.ToString(objItem[objTreeViewControlField.KeyColumn]);

                        objNodeTitle = Convert.ToString(objItem[objTreeViewControlField.ValueColumn]);
                        if (!String.IsNullOrEmpty(objNodeTitle))
                        {
                            TreeNode childNode = new TreeNode();
                            childNode.Text = objNodeTitle;
                            childNode.Value = objKeyColumn;
                            childNode.ExpandAll();

                            if (valueArray != null && this.ControlMode == SPControlMode.Edit && valueArray.Contains(childNode.Value))
                            {
                                childNode.ShowCheckBox = true;
                                childNode.Checked = true;
                            }
                            else if (this.ControlMode == SPControlMode.Display)
                            {
                                childNode.ShowCheckBox = false;
                            }
                            else
                            {
                                childNode.ShowCheckBox = true;
                            }

                            foreach (TreeNode cnode in GetChildNode(RootNode, valueArray, objListItemColn))
                            {
                                childNode.ChildNodes.Add(cnode);
                                cnode.SelectAction = TreeNodeSelectAction.None;
                                if (valueArray != null && this.ControlMode == SPControlMode.Edit && valueArray.Contains(cnode.Value))
                                {
                                    cnode.ShowCheckBox = true;
                                    cnode.Checked = true;
                                }
                                else if (this.ControlMode == SPControlMode.Display)
                                {
                                    cnode.ShowCheckBox = false;
                                }
                                else
                                {
                                    cnode.ShowCheckBox = true;
                                }
                            }
                            childtreenodes.Add(childNode);
                        }
                    }
                }
                return childtreenodes;
            }
            catch (Exception ex)
            {
                throw new Exception(GlobalConstants.ERROR_MESSAGE_CHILDNODE_CREATION_FAILED + GlobalConstants.HTML_BR + ex.Message);
            }
            // Call method again (recursion) to get the child items
        }
        private void CompletaAlbero(TreeNodeCollection nodes, Business.Entity.Categorie categorie)
        {
            var numProd = AnnunciCategorieCollection.GetCount("IdCategorie == " + categorie.Id);

            //Prendo la categoria con la lingua di default
            var cat = Business.Entity.Categorie.GetItem(Business.Entity.Categorie.KeyColumnsEnum.Id, categorie.Id);
            TreeNode node = new TreeNode(cat.Nome + " (" + numProd + ")", cat.Id.ToString());
            if (NodiEspansi.Contains(cat.Id)) node.ExpandAll();

            foreach (var item in CategorieCollection.GetList(wherePredicate: "IdPrec == @0", whereValues: new object[] { categorie.Id }, orderPredicate: "Posizione ASC")) CompletaAlbero(node.ChildNodes, item);
            nodes.Add(node);
        }
        private TreeNodeCollection GetChildNode(string RootNode, string[] valueArray, List<SPListItem> objListItemColn)
        {
            TreeNodeCollection childtreenodes = new TreeNodeCollection();
            SPQuery objSPQuery;
            SPListItemCollection objItems = null;
            List<SPListItem> objNodeListItems = new List<SPListItem>();
            SiteMapNodeCollection objNode = new SiteMapNodeCollection();
            objSPQuery = new SPQuery();
            string objNodeTitle = string.Empty;
            string objLookupColumn = string.Empty;
            StringBuilder Query = new StringBuilder();
            SPList objTaskList;
            SPField spField;
            objTaskList = SPContext.Current.Web.Lists[objTreeViewControlField.ListName];
            objLookupColumn = objTreeViewControlField.ParentLookup;
            
            spField = SPContext.Current.Web.Lists[objTreeViewControlField.ListName].Fields[objTreeViewControlField.ParentLookup];
            if (this.ControlMode == SPControlMode.Display)
            {
                objNodeListItems = (from SPListItem Item in objListItemColn
                                    where (new SPFieldLookupValue(Convert.ToString(Item[objTreeViewControlField.ParentLookup])).LookupValue == RootNode)
                                    orderby Item.ID
                                    select Item).ToList();

            }
            else
            {
                Query.Append(String.Format("<Where><Eq><FieldRef Name='" + spField.InternalName + "' /><Value Type='LookupMulti'>{0}</Value></Eq></Where>", RootNode));
                objSPQuery.Query = Query.ToString();


                objItems = objTaskList.GetItems(objSPQuery);
                foreach (SPListItem objItem in objItems)
                {
                    objNodeListItems.Add(objItem);
                }

            }
            if (objNodeListItems != null && objNodeListItems.Count > 0)
            {
                foreach (SPListItem objItem in objNodeListItems)
                {
                    RootNode = Convert.ToString(objItem[GlobalConstants.LIST_COLUMN_TITLE]);
                    objNodeTitle = Convert.ToString(objItem[objTreeViewControlField.ValueColumn]);
                    if (!String.IsNullOrEmpty(objNodeTitle))
                    {
                        TreeNode childNode = new TreeNode();
                        childNode.Text = objNodeTitle;
                        childNode.Value = RootNode;
                        childNode.ExpandAll();

                        if (valueArray != null && this.ControlMode == SPControlMode.Edit && valueArray.Contains(childNode.Value))
                        {
                            childNode.ShowCheckBox = true;
                            childNode.Checked = true;
                        }
                        else if (this.ControlMode == SPControlMode.Display)
                        {
                            childNode.ShowCheckBox = false;
                        }
                        else
                        {
                            childNode.ShowCheckBox = true;
                        }




                        foreach (TreeNode cnode in GetChildNode(RootNode, valueArray, objListItemColn))
                        {
                            childNode.ChildNodes.Add(cnode);
                            cnode.SelectAction = TreeNodeSelectAction.None;
                            if (valueArray != null && this.ControlMode == SPControlMode.Edit && valueArray.Contains(cnode.Value))
                            {
                                cnode.ShowCheckBox = true;
                                cnode.Checked = true;
                            }
                            else if (this.ControlMode == SPControlMode.Display)
                            {
                                cnode.ShowCheckBox = false;
                            }
                            else
                            {
                                cnode.ShowCheckBox = true;
                            }
                        }

                        childtreenodes.Add(childNode);
                    }
                }

            }
            return childtreenodes;



            // Call method again (recursion) to get the child items



        }