private void CreateDataTableNodes(DataTable dataSource, zTreeNode parentNode) { if (dataSource.Rows.Count == 0) { return; } var hasChild = !this.ParentIdField.IsEmpty(); DataRowCollection rows; var parentId = parentNode == null ? this.RootId : parentNode.Id; if (hasChild) { var dv = (dataSource as DataTable).DefaultView; dv.RowFilter = this.ParentIdField + "='" + parentId + "'"; rows = dv.ToTable().Rows; } else { rows = dataSource.Rows; } var nodes = parentNode == null ? this.Nodes : parentNode.Nodes; var args = new zTreeNodeDataBoundEventArgs(); foreach (DataRow row in rows) { var node = new zTreeNode(row[this.IdField].AsString(), row[this.NameField].AsString()); node.ParentNode = parentNode; nodes.Add(node); args.Node = node; args.DataItem = row; OnNodeDataBound(args); CreateDataTableNodes(dataSource, node); } }
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); } } }
public zTreeNodeDataBoundEventArgs(object dataItem, zTreeNode node) : base() { this.DataItem = dataItem; this.Node = node; }