Welcome Guest Search | Active Topics | Sign In | Register

How do I expand path on auto-populated tree view Options
Mike Wynn
Posted: Thursday, March 6, 2008 6:05:48 AM
Rank: Advanced Member
Groups: Member

Joined: 8/24/2007
Posts: 130
Hi,

I have a situation where a tree view is built dynamically by the user. Because the tree view is starting to get rather large, I am looking to build it useing auto populate.

I have a requirement that when the user creates a node in the tree (via a postback), that the tree is expanded to this new node. I currently do this using the ExpandPath method, however, am not sure how to do this when auto-populating the tree.

I notice that on postback, the tree always reverts to fully collapsed. Is there anyway of preserving the expanded state of the tree between postbacks?

I have read the discussion thread entitled "TreeView: After ExpandPath is called Server Side TreeNode On Click not called", which seems to discuss this topic. However, I do not see the NodePopulate handlers being called in relay, as this post suggests.
eo_support
Posted: Thursday, March 6, 2008 6:13:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

Most of the time that is caused by your code trying to recreate/rebind the TreeView. Try it with a blank page and an empty TreeView with only one static initial node, you will see NodePopulate being called in relay.

The same situation would interfere the expand/collapse state. I believe the TreeView automatically saves these states unless it is being wiped out by you.

Thanks
Mike Wynn
Posted: Thursday, March 6, 2008 6:24:23 AM
Rank: Advanced Member
Groups: Member

Joined: 8/24/2007
Posts: 130
Thanks for the quick reply...

I have set up a very simple page, as shown below, and am not seeing NodePopulate being called in relay on postback. After expanding the tree, when I cause a postback by clicking the button the tree collapses again.

Code: HTML/ASPX
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="WebForm1.aspx.cs" Inherits="IIPay.Web.WebForm1" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <eo:TreeView runat="server" ID="TreeView1" ControlSkinID="None"
                Width="250px" Height="280px">
                <TopGroup Style-CssText="border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;">
                    <Nodes>
                        <eo:TreeNode PopulateOnDemand="True" Text="1">
                        </eo:TreeNode>
                    </Nodes>
                </TopGroup>
                <LookNodes>
                    <eo:TreeNode ImageUrl="00030203" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;"
                        CollapsedImageUrl="00030301" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"
                        ExpandedImageUrl="00030302" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;">
                    </eo:TreeNode>
                </LookNodes>
            </eo:TreeView>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </div>
    </form>
</body>
</html>


Code: C#
public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TreeView1.ItemPopulate += new EO.Web.NavigationItemEventHandler(bindingTree_ItemPopulate);
        }

        static void bindingTree_ItemPopulate(object sender, EO.Web.NavigationItemEventArgs e)
        {
            //Get the parent node
            EO.Web.TreeNode parentNode = (EO.Web.TreeNode)e.NavigationItem;

            EO.Web.TreeNode node = new EO.Web.TreeNode((Convert.ToInt32(parentNode.Text) + 1).ToString());
            node.ItemID = node.Text;
            node.PopulateOnDemand = node.ItemID != "4";
            parentNode.SubGroup.Nodes.Add(node);
        }
    }
eo_support
Posted: Thursday, March 6, 2008 6:28:54 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

You should not hook up the event handler in Page_Load. It's too late. When ItemPopulate is replayed, it's triggered before Page_Load. Try to declare it directly in your .aspx file as:

<eo:TreeView OnItemPopulate="TreeView1_ItemPopulate" ...>

Thanks
Mike Wynn
Posted: Thursday, March 6, 2008 8:18:08 AM
Rank: Advanced Member
Groups: Member

Joined: 8/24/2007
Posts: 130
Thank you for that. Making this change now retains my tree view on post back. I have more help to request however.

I stated that my treeview is build up dynamically be the user. Currently, when a user requests a new tree node, in the postback handler I ammend the datasource appropriately, and re-bind the tree. Now that I wish to use populate on demand, I can no longer do it this way. How would you recommend that I go about this? The required behaviour is that when a new node is requested, on postback the treeview will retain its current expansion, but with the new node added and selected. I read in the thread that I quoted earlier, "nodes populated during page load will not be recognized as a source node to trigger item click event". Not sure how to proceed....

Thanks
eo_support
Posted: Thursday, March 6, 2008 8:33:50 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

I think you can just insert the node directly with code instead of rebinding the whole TreeView because rebinding the TreeView wipes out everything. However, populate on demand is only triggered when the node is being expanded, and I would expect adding node is triggered by something else. So I am not sure if they work well together though.

Thanks
Mike Wynn
Posted: Tuesday, March 11, 2008 2:59:08 AM
Rank: Advanced Member
Groups: Member

Joined: 8/24/2007
Posts: 130
Hi, thanks for the help on this. I have made much progress here, but still have a very frustrating issues that I cannot solve....

My treeview is a represesntation of an underlying object graph. I build the treeview using auto-populate.
On various nodes of the treeview, I provide context menus, that enable the user to create a new child node.
Previously, I would simply add the new object to my object model, and re-bind the tree.
However, now that I am using auto-populate, I cannot do this. Instead, I add the new object to the object model, and add the new node manually.
The problem that I am having, is that whenever I add a new node to the tree, the ItemPopulate handler does not get called when I attempt to expand other nodes. Note the following, however:
1. A postback will always fix this problem
2. The problem only occurs when I create the first child node (If I am crating a child node where other children exist, the problem does not occur)
3. When the problem occurs, the system does attempt to expand the nodes correctly (I get the Loading... message), it just doesn't seem to be hooked into the ItemPopulate handler.

I hope you have some insight here, as I have been struggling on this for a while. Cannot reallys send sample code, as it is too large.

Thank you.


eo_support
Posted: Tuesday, March 11, 2008 7:25:17 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

To be honest, I am not sure if I get what you are describing. So we definitely need an isolated sample code here. It got to do with your code. You may also want to try ItemPopulate in an empty event and see how it works.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.