Shashi
Shashi

Reputation: 2898

how to reduce the time taken to populate tree node in asp.net c# treeview?

I am binding the XML Data to treeview using XMLDataSource. Its working fime, but when the Number of nodes and childnodes increases, the treenode expand and to display the content in iframe takes moer time.

<asp:TreeView ID="TreeView1"  OnSelectedNodeChanged = "OnClick" runat="server" 
                    ExpandDepth="0"  ShowExpandCollapse="true" ForeColor="Red" Font-Underline = "false" 
                    ondatabinding="TreeView1_DataBinding" CollapseImageUrl = "Resources/TocColapse.bmp" ExpandImageUrl = "Resources/TocParent.bmp" Font-Names="Arial"   >
                    <SelectedNodeStyle Font-Underline="false" BackColor="White" ForeColor="#0483e0" />
                    <NodeStyle Font-Size="11pt" ForeColor="white" HorizontalPadding="5px"
                        NodeSpacing="0px" VerticalPadding="0px" Font-Underline = "false" />
                    <ParentNodeStyle ForeColor="#0483e0" Font-Underline = "false" />
                    <LeafNodeStyle ForeColor="#0483e0" Font-Underline = "false" ImageUrl = "Resources/TocChild.bmp"  />

                </asp:TreeView>
                <asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="/*/*" EnableCaching = "false" ></asp:XmlDataSource>

In OnDataBinding event of treeview I implemented the following code:

 TreeNodeBinding[] TreeNode = new TreeNodeBinding[Count];
        for (int i = 0; i < Count; i++)
        {
            TreeNode[i] = new TreeNodeBinding();
            TreeNode[i].DataMember = TableOfContents[i].GetElementName();
            TreeNode[i].TextField = TableOfContents[i].GetFirstAttributeName();
            TreeNode[i].ValueField = TableOfContents[i].GetSecondAttributeName();
            // TreeNode[i].Target = "contentFrame";
            TreeView1.DataBindings.Add(TreeNode[i]);
        }

Upvotes: 0

Views: 773

Answers (3)

Vickyonit
Vickyonit

Reputation: 1197

Try for populate on demand.

I used populate on demand when it was taking so long time in loading the treeview in the client side.

Upvotes: 0

codymanix
codymanix

Reputation: 29490

What about setting EnableCaching to "true"?

Also, are you sure that you need to display the whole xml? You could provide the user some filtering which reduces the size of the displayed xml.

Upvotes: 0

Cromathaar
Cromathaar

Reputation: 64

Of course it does. Take a look towards lazy loading.

Upvotes: 2

Related Questions