[CLOSED] Treepanel in User Control

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] Treepanel in User Control

    Hi, I have the following problem with the control TreePanel:

    I include a TreePanel in a UserControl, it codified a public property in which I set the DataSource (IList), the problem is that when the page does a posback the DataSource property value is lost and the function that generates the json for the tree no longer works. To solve this problem I keep a variable in viewstate the DataSource. Now the problem is another because the page weighs more than 2 mb because the tree contains more than 500 nodes and the page no longer reender.

    As might solve the loss of the DataSource?

    this is my UserControl, thanks..

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucCustomTree.ascx.cs"
        Inherits="Misc.UserControls.ucCustomTree" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <ext:Hidden ID="hidValue" runat="server" />
    <ext:Hidden ID="hidID" runat="server" />
    <ext:Hidden ID="hidValueAll" runat="server" />
    <ext:Hidden ID="hidCollapsed" runat="server" />
    <ext:Hidden ID="hidControlRenderMode" runat="server" />
    <ext:Hidden ID="hidControlBehavior" runat="server" />
    <ext:Hidden ID="hidRestrictToLowerLevel" runat="server" />
    <ext:Hidden ID="hidAllowMultipleSelection" runat="server" />
    <ext:Hidden ID="hidDisabled" runat="server" />
    <script language="javascript" type="text/javascript">
        var filterTree = function (el, e) {
            
            var tree = el.ownerCt.ownerCt,
                text = this.getRawValue();
            tree.clearFilter(el);
            if (Ext.isEmpty(text, false)) { return; }
            if (e.getKey() === Ext.EventObject.ESC) {
                clearFilter(el);
            } else {
                var re = new RegExp(".*" + text + ".*", "i");
                tree.filterBy(function (node) {
                    return re.test(node.text);
                });
            }
        };
    
        var clickDropDown = function (node, ddf, allowMultipleSelection, hidValue, restrictToLowerLevel) {
            
            if (allowMultipleSelection.value == 'True')
                return;
    
            hidValue.setValue('');
    
            if (restrictToLowerLevel.value == "True") {
                if (node.childNodes.length > 0)
                    return;
            }
            ddf.setValue(getValue(node, hidValue), getText(node), false);
            ddf.collapse();
        };
    
        var toggleParents = function (node) {
            
            if (node.parentNode != null && node.getUI().checkbox.checked == false) {
                if (node.parentNode.getUI().checkbox != null) {
                    node.parentNode.getUI().checkbox.checked = node.getUI().checkbox.checked;
                    toggleParents(node.parentNode);
                }
            }
        };
    
        var toggleParents2 = function (node) {
    
            if (node.parentNode != null && node.getUI().checkbox.checked == true) {
                if (node.parentNode.getUI().checkbox != null) {
                    node.parentNode.getUI().checkbox.checked = node.getUI().checkbox.checked;
                    toggleParents2(node.parentNode);
                }
            }
    
            if (node.parentNode != null && node.getUI().checkbox.checked == false) {
                if (node.parentNode.getUI().checkbox != null && node.parentNode.getUI().checkbox.checked == true) {
                    var allChildsFalse = false;
                    var nodeArray = node.parentNode.childNodes;
                    for (var i = 0; i < nodeArray.length; i++) {
                        if (nodeArray[i].getUI().checkbox.checked == true) {
                            allChildsFalse = true;
                        }
                    }
    
                    if (!allChildsFalse) {
                        node.parentNode.getUI().checkbox.checked = node.getUI().checkbox.checked; ;
                        toggleParents2(node.parentNode);
                    }
                }
            }
        };
    
        var clearFilter = function (el) {
            
            var tree = el.ownerCt.ownerCt;
            el.setValue("");
            tree.clearFilter(el);
            tree.getRootNode().collapseChildNodes(true);
        };
    
        var getSelected = function (node, controlBehavior) {
            if (controlBehavior.value == 'HandlerParentPath') {
                toggleParents2(node);
                if (!node.getUI().isChecked()) {
                    node.expand();
                    node.expandChildNodes(true);
                    node.eachChild(function (child) {
                        child.ui.toggleCheck(node.getUI().isChecked());
                        child.fireEvent('checkchange', child, node.getUI().isChecked());
                    })
                }
                else {
                    if (node.childNodes.length > 0) {
                        node.expand();
                        node.expandChildNodes(true);
                        node.eachChild(function (child) {
                            child.ui.toggleCheck(node.getUI().isChecked());
                            child.fireEvent('checkchange', child, node.getUI().isChecked());
                        })
                    }
                }
            }
            else {
                node.expand();
                node.expandChildNodes(true);
                node.eachChild(function (child) {
                    child.ui.toggleCheck(node.getUI().isChecked());
                    child.fireEvent('checkchange', child, node.getUI().isChecked());
                })
    
                toggleParents(node);
            }
        };
    
        var submitTreeCbo = function (tree, ddf, hidValue) {
    
            var msg = [];
            var txt = [];
    
            tree.root.eachChild(function (child) { submitCheckedCbo(child, msg, txt); });
    
            hidValue.setValue(msg.join(","));
        }
    
        var submitTree = function (tree, ddf, controlBehavior, hidValue) {
    
            var msg = [];
            var txt = [];
            if (controlBehavior.value == 'HandlerParentPath') {
                tree.root.eachChild(function (child) { submitChecked(child, msg, txt); });
            }
            else {
                tree.root.eachChild(function (child) { submitChecked2(child, msg, txt); });
            }
    
            hidValue.setValue(msg.join(","));
            if (ddf != null) {
                ddf.setValue(msg.join(","), txt.join(","), false);
            }
    
        }
    
        var submitCheckedCbo = function (node, msg, txt) {
    
            if (node.getUI().isChecked()) {
                msg.push(node.id);
                txt.push(node.text);
            }
            var nodeArray = node.childNodes;
            for (var i = 0; i < nodeArray.length; i++) {
                submitCheckedCbo(nodeArray[i], msg, txt);
            }
        };
    
        var submitChecked = function (node, msg, txt) {
            
            if (node.getUI().isChecked()) {
                msg.push(node.id);
                txt.push(node.text);
            }
            var nodeArray = node.childNodes;
            for (var i = 0; i < nodeArray.length; i++) {
                submitChecked(nodeArray[i], msg, txt);
            }
        };
    
        var submitChecked2 = function (node, msg, txt) {
    
            if (node.getUI().isChecked()) {
                msg.push(node.id);
                txt.push(node.text);
            }
            else {
                var nodeArray = node.childNodes;
                for (var i = 0; i < nodeArray.length; i++) {
                    submitChecked2(nodeArray[i], msg, txt);
                }
            }
        };
    
        var getSelectedDropDown = function (node, controlBehavior) {
            
            if (controlBehavior.value == 'HandlerParentPath') {
                toggleParents2(node);
            }
            else {
                node.expand();
                node.expandChildNodes(true);
                node.eachChild(function (child) {
                    child.ui.toggleCheck(node.getUI().isChecked());
                    //child.fireEvent('checkchange', child, node.getUI().isChecked());
                })
    
                toggleParents(node);
            }
        };
    
        var getSelected2 = function (node, allowMultipleSelection, hidValue, restrictToLowerLevel) {
            
            if (allowMultipleSelection.value == 'True')
                return;
    
            hidValue.setValue('');
    
            if (restrictToLowerLevel.value == 'True') {
                if (node.childNodes.length > 0)
                    return;
            }
            hidValue.setValue(node.id);
        };
    
        var getValue = function (node, hidValue) {
            
            hidValue.setValue(node.id);
            return node.id;
        };
    
        var getText = function (node) {
            
            return node.text;
        };
    
        var getIsChecked = function (node, msg) {
    
            if (node.checked) {
                msg.push(node.id);
            }
            var nodeArray = node.children;
            if (typeof (nodeArray) != 'undefined') {
                for (var i = 0; i < nodeArray.length; i++) {
                    getIsChecked(nodeArray[i], msg);
                }
            }
        };
    
        var getIsChecked2 = function (node, msg) {
    
            if (node.checked) {
                msg.push(node.id);
            }
            else {
                var nodeArray = node.children;
                if (typeof (nodeArray) != 'undefined') {
                    for (var i = 0; i < nodeArray.length; i++) {
                        getIsChecked2(nodeArray[i], msg);
                    }
                }
            }
        };
    
        var clearTree = function (tree, directMethods, controlBehavior, hidValue) {
            directMethods.LoadData({
                success: function (result) {
                    var nodes = eval(result);
                    if (nodes.length > 0) {
                        tree.initChildren(nodes);
                        var msg = [];
                        if (controlBehavior.value == 'HandlerParentPath') {
                            for (var ii = 0; ii < nodes[0].children.length; ii++)
                            { getIsChecked(nodes[0].children[ii], msg); };
                        }
                        else {
                            for (var ii = 0; ii < nodes[0].children.length; ii++)
                            { getIsChecked2(nodes[0].children[ii], msg); };
                        }
                        hidValue.setValue(msg.join(","));
                    }
                    else {
                        tree.getRootNode().removeChildren();
                    }
    
                }
            });
        }
    </script>
    <ext:Panel ID="pnlDD" runat="server" Border="false">
        <Items>
            <ext:DropDownField ID="ddfDropDownTree" runat="server" 
                Editable="false" 
                TriggerIcon="SimpleArrowDown"
                Mode="ValueText" 
                LazyInit="false">
                <Component>
                    <ext:TreePanel ID="trpDropDownTree" runat="server" 
                        UseArrows="true" 
                        AutoScroll="true"
                        Animate="false" 
                        EnableDD="false" 
                        ContainerScroll="true"  
                        AnimCollapse="false">
                        <Root>
                            <ext:TreeNode NodeID="root" Text="root" /> 
                        </Root>
                        <TopBar>
                            <ext:Toolbar ID="tbrDropDownTree" runat="server">
                                <Items>
                                    <ext:ToolbarTextItem ID="ttiDropDownFilter" runat="server" Text="Filter:" />
                                    <ext:ToolbarSpacer runat="server" />
                                    <ext:TriggerField ID="trfDropDownTrigger" runat="server" EnableKeyEvents="true">
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" />
                                        </Triggers>
                                        <Listeners>
                                            <KeyUp Fn="filterTree" Buffer="250" />
                                            <TriggerClick Handler="clearFilter(#{trfDropDownTrigger});" />
                                        </Listeners>
                                    </ext:TriggerField>
                                    <ext:ToolbarSpacer ID="ToolbarSpacer2" runat="server" />
                                    <ext:Button ID="btnClearDD" Icon="Delete" ToolTip="Clean Data" runat="server">
                                        <Listeners>
                                            <Click Handler="#{hidValue}.setValue(null);#{trpDropDownTree}.getRootNode().removeChildren();clearTree(#{trpDropDownTree}, #{DirectMethods}, #{hidControlBehavior}, #{hidValue});"/>
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSpacer ID="ToolbarSpacer5" runat="server" />
                                    <ext:Button ID="btnRefreshDD" Icon="RewindBlue" ToolTip="Refresh" Hidden="true" runat="server">
                                        <Listeners>
                                            <Click Handler="#{trpDropDownTree}.getRootNode().removeChildren();clearTree(#{trpDropDownTree}, #{DirectMethods}, #{hidControlBehavior}, #{hidValue});"/>
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Listeners>
                            <CheckChange Handler="getSelectedDropDown(node, #{hidControlBehavior}); 
                                submitTree(#{trpDropDownTree}, #{ddfDropDownTree}, #{hidControlBehavior}, #{hidValue});" />
                            <Click Handler="clickDropDown(node, #{ddfDropDownTree}, 
                                #{hidAllowMultipleSelection}, #{hidValue}, #{hidRestrictToLowerLevel});" />
                        </Listeners>
                        <SelectionModel>
                            <ext:DefaultSelectionModel ID="dsmDropDownTree" runat="server">
                            </ext:DefaultSelectionModel>
                        </SelectionModel>
                    </ext:TreePanel>
                </Component>
                <Listeners>
                    <Collapse Handler="submitTreeCbo(#{trpDropDownTree}, #{ddfDropDownTree}, #{hidValueAll});" />
                </Listeners>
            </ext:DropDownField>
        </Items>
    </ext:Panel>
    <ext:Panel ID="pnlTree" runat="server" Border="false">
        <Content>
            <ext:TreePanel ID="trpTree" runat="server" 
                UseArrows="true" 
                AutoScroll="true" 
                Animate="false"
                EnableDD="false" 
                ContainerScroll="true" 
                AnimCollapse="false">
                <Root>
                    <ext:TreeNode NodeID="root" Text="root" /> 
                </Root>
                <TopBar>
                    <ext:Toolbar ID="tobTree" runat="server">
                        <Items>
                            <ext:ToolbarTextItem ID="ttiTree" runat="server" Text="Filter:"/>
                            <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" />
                            <ext:TriggerField ID="trfTree" runat="server" EnableKeyEvents="true">
                                <Triggers>
                                    <ext:FieldTrigger Icon="Clear" />
                                </Triggers>
                                <Listeners>
                                    <KeyUp Fn="filterTree" Buffer="250" />
                                    <TriggerClick Handler="clearFilter(#{trfTree});" />
                                </Listeners>
                            </ext:TriggerField>
                            <ext:ToolbarSpacer ID="ToolbarSpacer3" runat="server" />
                            <ext:Button ID="btnClear" Icon="Delete" ToolTip="Clean Data" Hidden="false" runat="server">
                                <Listeners>
                                    <Click Handler="#{hidValue}.setValue(null);#{trpTree}.getRootNode().removeChildren();clearTree(#{trpTree}, #{DirectMethods}, #{hidControlBehavior}, #{hidValue});"/>
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarSpacer ID="ToolbarSpacer4" runat="server" />
                            <ext:Button ID="btnRefresh" Icon="RewindBlue" ToolTip="Refresh" Hidden="true" runat="server">
                                <Listeners>
                                    <Click Handler="#{trpTree}.getRootNode().removeChildren();clearTree(#{trpTree}, #{DirectMethods}, #{hidControlBehavior}, #{hidValue});"/>
                                </Listeners>
                            </ext:Button>
                            <ext:Label ID="lblRequired" Cls="requiredField" runat="server" Visible="false"></ext:Label>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Listeners>
                    <CheckChange Handler="getSelected(node, #{hidControlBehavior});
                                  submitTree(this, null, #{hidControlBehavior}, #{hidValue});" />
                    <Click Handler="getSelected2(node, #{hidAllowMultipleSelection}, #{hidValue}, #{hidRestrictToLowerLevel});" />
                </Listeners>
                <SelectionModel>
                    <ext:DefaultSelectionModel ID="dsmTree" runat="server">
                    </ext:DefaultSelectionModel>
                </SelectionModel>
            </ext:TreePanel>
        </Content>
    </ext:Panel>
    using System;
    using System.Activities.Expressions;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using Ext.Net;
    using WHTS.Business.Core;
    using WHTS.Common.Classes;
    using WHTS.Web.Pages;
    
    namespace Misc.UserControls
    {
        public partial class ucCustomTree : ContextUCPage
        {
            #region variables declarations
    
            public enum eRenderMode
            {
                Tree,
                DropDownField
            }
    
            public enum eBehavior
            {
                HandlerParentPath,
                HandlerChildPath
            }
    
            private string strRootName;
            private string strTextSelected;
            private bool NotAllowBlank;
    
            protected string strTooltip;
    
            //private string kViewStateName_DataSource = "KVIEW_DATASOURCE";
    
            #endregion
    
            protected void Page_Load(object sender, EventArgs e)
            {
                FormatControl();
            }
    
            #region Properties
    
            /// <summary>
            /// Get / Set how to render control (RenderMode.Tree or RenderMode.DropDownField)
            /// </summary>
            public eRenderMode RenderMode
            {
                get
                {
                    if (hidControlRenderMode.Value == null)
                    {
                        return eRenderMode.Tree;
                    }
    
                    return hidControlRenderMode.Value.ToString() == eRenderMode.DropDownField.ToString()
                               ? eRenderMode.DropDownField
                               : eRenderMode.Tree;
                }
                set
                {
                    hidControlRenderMode.Value = value.ToString();
                    if (value == eRenderMode.Tree)
                    {
                        pnlDD.Visible = false;
                    }
                    else
                    {
                        pnlTree.Visible = false;
                    }
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public eBehavior Behavior
            {
                get
                {
                    if (hidControlBehavior.Value == null)
                    {
                        return eBehavior.HandlerChildPath;
                    }
    
                    return hidControlBehavior.Value.ToString() == eBehavior.HandlerChildPath.ToString()
                               ? eBehavior.HandlerChildPath
                               : eBehavior.HandlerParentPath;
                }
                set { hidControlBehavior.Value = value.ToString(); }
            }
    
            /// <summary>
            /// This property lets you specify whether the selection is allowed only on lower levels. If this setpoint (= false) is allowed on any level.
            /// </summary>
            public bool RestrictToLowerLevel
            {
                get
                {
                    if (hidRestrictToLowerLevel.Value == null)
                    {
                        return true;
                    }
    
                    return hidRestrictToLowerLevel.Value.ToString() == true.ToString() ? true : false;
                }
                set { hidRestrictToLowerLevel.Value = value.ToString(); }
            }
    
            /// <summary>
            /// Specify whether you can select more than one value. By default this will be true.
            /// </summary>
            public bool AllowMultipleSelection
            {
                get
                {
                    if (hidAllowMultipleSelection.Value == null)
                    {
                        return true;
                    }
    
                    return hidAllowMultipleSelection.Value.ToString() == true.ToString() ? true : false;
                }
                set { hidAllowMultipleSelection.Value = value.ToString(); }
            }
    
            /// <summary>
            /// Level for the renderer. The same can act together with the property RestrictToLowerLevel act only as a last at that level.
            /// </summary>
            public int MaxLevel { get; set; }
    
            /// <summary>
            /// Tree Data to render.
            /// </summary>
            public IList DataSource  { get; set; }
            //{
            //    get { return (IList)ViewState[kViewStateName_DataSource]; }
            //    set
            //    {
            //        if (ViewState[kViewStateName_DataSource] == null)
            //        {
            //            //ViewState.Add(kViewStateName_DataSource, value);
            //        }
            //        else
            //        {
            //            //ViewState[kViewStateName_DataSource] = value;
            //        }
            //    }
            //}
    
            /// <summary>
            /// Determinate de Root name of tree.
            /// </summary>
            public string RootName
            {
                get
                {
                    return strRootName;
                }
                set
                {
                    strRootName = value;
    
                    trpTree.Root[0].Text = strRootName;
                    trpDropDownTree.Root[0].Text = strRootName;
                }
            }
    
            /// <summary>
            /// Control Width
            /// </summary>
            public string Width { get; set; }
    
            /// <summary>
            /// 
            /// </summary>
            public string AnchorHorizontal{ get; set; }
    
            /// <summary>
            /// Control Height
            /// </summary>
            public string Height{ get; set; }
    
            public string MinHeightBoxArea{ get; set; }
    
            public string MinWidthBoxArea { get; set; }
    
            public double BoxWidth{ get; set; }
    
            public double BoxHeight{ get; set; }
    
            /// <summary>
            /// 
            /// </summary>
            public string AnchorVertical{ get; set; }
    
            /// <summary>
            /// 
            /// </summary>
            public bool ShowRootName
            { 
                get { return RenderMode == eRenderMode.Tree ? trpTree.RootVisible : trpDropDownTree.RootVisible; }
                set
                {
                    if (RenderMode == eRenderMode.Tree)
                    {
                        trpTree.RootVisible = value;
                    }
                    else
                    {
                        trpDropDownTree.RootVisible = value;
                    }
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public List<string> Value
            {
                get
                {
                    if (hidValue.Value == null || hidValue.Value.ToString() == string.Empty)
                    {
                        return null;
                    }
                    return hidValue.Value.ToString().Split(',').ToList();
                }
                set
                {
                    hidValue.Value = value == null ? null : string.Join(",", value);
                }
            }
    
            public List<string> ValueComplete
            {
                get
                {
                    if (hidValueAll.Value == null || hidValueAll.Value.ToString() == string.Empty)
                    {
                        return null;
                    }
                    return hidValueAll.Value.ToString().Split(',').ToList();
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public string DataTextField { get; set; }
    
            /// <summary>
            /// 
            /// </summary>
            public string DataValueField { get; set; }
    
            /// <summary>
            /// 
            /// </summary>
            public string DataTooltipField
            {
                get
                {
                    return string.IsNullOrEmpty(strTooltip) ? DataTextField : strTooltip;
                }
                set
                {
                    strTooltip = value;
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public string DataNodeParentTreePathField { get; set; }
    
            /// <summary>
            /// 
            /// </summary>
            public string FieldLabel
            {
                get { return ddfDropDownTree.FieldLabel; }
                set
                {
                    ddfDropDownTree.FieldLabel = TranslationsBsn.TranslateText(value);
                    trpTree.FieldLabel = ddfDropDownTree.FieldLabel;
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            public bool Collapsed { get; set; }
    
            public bool RequiredField { get { return NotAllowBlank; } set { NotAllowBlank = value; } }
    
            public int LabelWidth { get; set; }
    
            public bool IsValid
            {
                get {
                    return !RequiredField || Value != null;
                }
            }
    
            public bool Disabled
            {
                get { return Convert.ToBoolean(hidDisabled.Value.ToString()); }
                set { hidDisabled.Value = value.ToString();
                    if (RenderMode == eRenderMode.DropDownField)
                    {
                        ddfDropDownTree.Disabled = value;
                    }}
            }
    
            #endregion
    
            #region Public methods
    
            /// <summary>
            /// 
            /// </summary>
            public void ClearSelection()
            {
                Value = null;
                if (RenderMode == eRenderMode.Tree)
                {
                    btnRefresh.FireEvent("Click");
                }
            }
    
    
            /// <summary>
            /// 
            /// </summary>
            public void LoadTreeCheckbox()
            {
                if (RenderMode == eRenderMode.Tree)
                {
                    btnRefresh.FireEvent("Click");
                }
            }
            
            /// <summary>
            /// 
            /// </summary>
            public new void DataBind()
            {
                if (RenderMode == eRenderMode.Tree)
                {
                    BuildTree(trpTree.Root, false);
                }
                else
                {
                    BuildTree(trpDropDownTree.Root, false);
    
                    ddfDropDownTree.SetValue(string.Empty, string.Empty);
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            [DirectMethod]
            public string LoadData()
            {
                TreeNodeCollection nodes = null;
    
                if (RenderMode == eRenderMode.Tree)
                    nodes = BuildTree(trpTree.Root, true);
                else
                {
                    strTextSelected = string.Empty;
                    nodes = BuildTree(trpDropDownTree.Root, true);
                    if (hidValue.Value != null)
                    {
                        string strValues = string.Empty;
                        strValues = hidValue.Value.ToString();
                        ddfDropDownTree.SetValue(strValues, strTextSelected);
                    }
                    else
                    {
                        ddfDropDownTree.SetValue(string.Empty, strTextSelected);
                    }
                }
    
                if (RenderMode == eRenderMode.DropDownField)
                {
                    if (RequiredField)
                    {
                        if (hidValue.Value == null || hidValue.Value.ToString() == string.Empty)
                            ddfDropDownTree.MarkInvalid();
                        else
                            ddfDropDownTree.ClearInvalid();
                    }
                    else
                        ddfDropDownTree.ClearInvalid();
                }
    
                return nodes.ToJson();
            }
    
            public void RefreshCbo()
            {
                btnRefreshDD.FireEvent("Click");
            }
    
            #endregion
    
            #region private methods
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="trnParent"></param>
            /// <param name="lstCustomTreeParent"></param>
            private void CreateNode(
                TreeNode trnParent,
                IEnumerable lstCustomTreeParent)
            {
                string strPatentAux;
    
                foreach (Object CustomTree in lstCustomTreeParent)
                {
                    bool blnDisabled;
    
                    if (hidDisabled.Value != null && hidDisabled.Value.ToString() != string.Empty && Convert.ToBoolean(hidDisabled.Value.ToString()))
                        blnDisabled = true;
                    else
                        blnDisabled = false;
    
                    TreeNode treeNode = new TreeNode
                    {
                        NodeID =
                            ReflectionFunctions.ReadProperty(CustomTree, DataValueField).ToString(),
                        Text =
                            ReflectionFunctions.ReadProperty(CustomTree, DataTextField).ToString(),
                        Qtip =
                            ReflectionFunctions.ReadProperty(CustomTree, DataTooltipField).ToString(),
                        Expanded = !Collapsed,
                        AllowDrag = false,
                        AutoDataBind = false,
                        AllowDrop = false
                    };
    
                    strPatentAux = ReflectionFunctions.ReadProperty(CustomTree, DataValueField).ToString().ToLower();
    
                    int intLevel = strPatentAux.Split('|').Count();
    
                    if (MaxLevel == 0)
                        MaxLevel = 99999999;
    
                    if (intLevel < MaxLevel)
                    {
                        string aux = strPatentAux;
                        IList lstCustomTreesHijos =
                            (from productHijos in DataSource.Cast<object>()
                             where ReflectionFunctions.ReadProperty(productHijos, DataNodeParentTreePathField) != null
                                   &&
                                   ReflectionFunctions.ReadProperty(productHijos, DataNodeParentTreePathField).ToString().ToLower() == aux
                             select productHijos).ToList();
    
                        CreateNode(treeNode, lstCustomTreesHijos);
                    }
    
                    if (RestrictToLowerLevel)
                    {
                        if (treeNode.Nodes.Count == 0)
                        {
                            if (AllowMultipleSelection)
                                CheckNode(treeNode, blnDisabled);
                            else
                                SelectNode(treeNode, blnDisabled);
                        }
                        else
                        {
                            treeNode.Disabled = true;
                        }
                    }
                    else
                    {
                        if (AllowMultipleSelection)
                            CheckNode(treeNode, blnDisabled);
                        else
                            SelectNode(treeNode, blnDisabled);
                    }
    
                    trnParent.Nodes.Add(treeNode);
                }
            }
    
            private void SelectNode(TreeNode treeNode,bool blnDisabled)
            {
                if (blnDisabled && RenderMode == eRenderMode.Tree)
                {
                    trpTree.DisableNode(treeNode.NodeID);
                }
                if (!blnDisabled && RenderMode == eRenderMode.Tree)
                {
                    trpTree.EnableNode(treeNode.NodeID);
                }
    
                if (Value != null)
                {
                    if (Value.Contains(treeNode.NodeID))
                    {
                        if (RenderMode == eRenderMode.Tree)
                            trpTree.SelectNode(treeNode.NodeID);
                        else
                            trpDropDownTree.SelectNode(treeNode.NodeID);
                        if (strTextSelected != string.Empty)
                            strTextSelected += ",";
                        strTextSelected += treeNode.Text;
                    }
                }
                else
                {
                    if (RenderMode == eRenderMode.Tree)
                        trpTree.UnselectNode(treeNode.NodeID);
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="nodeID"></param>
            /// <summary>
            /// 
            /// </summary>
            /// <param name="treeNode"></param>
            /// <param name="blnDisabled"></param>
            private void CheckNode(TreeNode treeNode, bool blnDisabled)
            {
                treeNode.Disabled = blnDisabled;
    
                if (Value != null && Value.Count > 0)
                {
                    treeNode.Checked = Value.Contains(treeNode.NodeID) ? ThreeStateBool.True : ThreeStateBool.False;
                    if (treeNode.Checked == ThreeStateBool.True)
                    {
                        if (strTextSelected != string.Empty)
                            strTextSelected += ",";
                        strTextSelected += treeNode.Text;
                    }
                }
                else
                {
                    treeNode.Checked = ThreeStateBool.False;
                }
            }
    
            private TreeNodeCollection BuildTree(TreeNodeCollection nodes, bool clear)
            {
                TreeNode root = (TreeNode)nodes[0];
    
                if (clear)
                {
                    root.Nodes.Clear();
                }
    
                if (DataSource != null)
                {
                    IList lstParentsCustomTrees =
                        (from CustomTree in DataSource.Cast<object>()
                         where ReflectionFunctions.ReadProperty(CustomTree, DataNodeParentTreePathField) == null
                         select CustomTree).ToList();
                    CreateNode(root, lstParentsCustomTrees);
                }
    
                return nodes;
            }
    
            #endregion
    
            private void FormatControl()
            {
                if (RenderMode == eRenderMode.Tree)
                {
                    if (AnchorHorizontal != null)
                        trpTree.AnchorHorizontal = AnchorHorizontal;
                    else
                        trpTree.Width = System.Web.UI.WebControls.Unit.Parse(Width);
                    
                    if (AnchorVertical != null)
                        trpTree.AnchorVertical = AnchorVertical;
                    else
                        trpTree.Height = System.Web.UI.WebControls.Unit.Parse(Height);
                    
                    if (LabelWidth != 0)
                        trpTree.LabelWidth = LabelWidth;
    
                    lblRequired.Visible = NotAllowBlank;
                    btnClear.Hidden = NotAllowBlank;
                    lblRequired.Text = TranslationsBsn.TranslateText("Required");
                }
                else
                {
                    if (AnchorHorizontal != null)
                        ddfDropDownTree.AnchorHorizontal = AnchorHorizontal;
                    else
                        ddfDropDownTree.Width = System.Web.UI.WebControls.Unit.Parse(Width);
                    
                    if (AnchorVertical != null)
                        ddfDropDownTree.AnchorVertical = AnchorVertical;    
                    else
                        ddfDropDownTree.Height = System.Web.UI.WebControls.Unit.Parse(Height);
                    trpDropDownTree.SetSize((int) BoxWidth, (int) BoxHeight);
                    trpDropDownTree.BoxMinHeight = System.Web.UI.WebControls.Unit.Parse(MinHeightBoxArea);
                    trpDropDownTree.BoxMinWidth = System.Web.UI.WebControls.Unit.Parse(MinWidthBoxArea);
                    
                    if (LabelWidth != 0)
                        ddfDropDownTree.LabelWidth = LabelWidth;
    
                    if (NotAllowBlank)
                    {
                        ddfDropDownTree.Cls = "requiredField";
                        btnClearDD.Hide();
                    }
                    else
                    {
                        ddfDropDownTree.Cls = "";
                        btnClearDD.Show();
                    }
    
                    ddfDropDownTree.AllowBlank = !NotAllowBlank;
                }
            }
        }
    }
    Last edited by Daniil; Oct 28, 2010 at 3:07 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I would suggest to store the DataSource in the Session or Cache, not ViewState.

    To reduce page's size it's recommended to disable ViewState at all.
    Last edited by Daniil; Oct 26, 2010 at 7:42 PM.

Similar Threads

  1. Replies: 7
    Last Post: Jan 29, 2013, 11:59 AM
  2. Replies: 2
    Last Post: Feb 06, 2012, 9:06 AM
  3. [CLOSED] Issue with TreePanel scrolling when placed in User Control (1.0)
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 03, 2011, 4:39 AM
  4. how to upload user control dynamicaly on user control
    By archana mahadule in forum 1.x Help
    Replies: 1
    Last Post: Jan 13, 2011, 12:05 PM
  5. Replies: 2
    Last Post: Aug 27, 2009, 8:12 AM

Posting Permissions