Esempio n. 1
0
        private void CreatezTreeNodes(IEnumerable dataSource, zTreeNode parentNode)
        {
            var query    = dataSource.AsQueryable();
            var dataType = query.ElementType;
            var idPI     = GetPropertyInfo(dataType, this.IdField);
            var namePI   = GetPropertyInfo(dataType, this.NameField);
            var hasChild = !this.ParentIdField.IsEmpty();
            var parentId = parentNode == null ? this.RootId : parentNode.Id;

            if (hasChild)
            {
                query = query.Where(this.ParentIdField + "==@0", parentId);
            }
            var nodes = parentNode == null ? this.Nodes : parentNode.Nodes;
            var args  = new zTreeNodeDataBoundEventArgs();

            foreach (var row in query)
            {
                if (parentNode != null && !parentNode.IsParent)
                {
                    parentNode.IsParent = true;
                }
                var node = new zTreeNode(idPI.GetValue(row, null).AsString(), namePI.GetValue(row, null).AsString());
                node.ParentNode = parentNode;
                node.IsParent   = this.ParentIdField.IsEmpty();
                nodes.Add(node);
                args.Node     = node;
                args.DataItem = row;
                OnNodeDataBound(args);
                if (hasChild)
                {
                    CreatezTreeNodes(dataSource, node);
                }
            }
        }