This is a migrated thread and some comments may be shown as answers.

TreeList Remembers State After Rebind?

3 Answers 92 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Joel Kraft
Top achievements
Rank 2
Joel Kraft asked on 23 Jul 2013, 11:50 PM
I have been working with an organizational chart and have noticed some odd behavior when working with a Rebind on postback.

I have attached some screen shots to show what is happening.
First I bound the grid to me.  I have four subordinates with no other subordinates.
I expanded my node to show the subordinates, then I clicked the expand on two of them.
The result is in FirstBind.png, and it looks exactly as expected.

THEN, I call Rebind() on the tree and rebind with MY supervisor at the root of the tree. What is unexpected here, is that even though this was a complete rebind, MY part of the tree remains expanded in exactly the same way that it was before the rebind.  You can see that my node is expanded, and that the expand markers for the two subordinates that I attempted to expand earlier have disappeared.  This is in SecondBind.png.

This does not seem expected to me.  I could see this information being persisted if I was doing some other sort of a postback, but on a Rebind(), I think everything should be reset.

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 26 Jul 2013, 11:07 AM
Hi Joel,

Could you please provide your code declaration and the related code behind in order to investigate the issue further. Additionally what kind of data binding you are using, simple data binding or advanced data binding. If you are using simple data binding I would recommend you to use advanced one. More information on this matter could be found at the following help article.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Joel Kraft
Top achievements
Rank 2
answered on 26 Jul 2013, 03:15 PM
This is using advanced binding, and load on demand for child nodes.
Even coming up with this example was trying.

  1. Open Page
  2. Expand James (see two children)
  3. Expand Sam & Roger (no children and expand option disappears)
  4. Click Radio Button to option B, this causes an explicit rebind
  5. Notice that there is no expansion option for Dave!
  6. Click Radio Button to option B, this causes an explicit rebind and collapses all nodes
  7. Expand Dave
  8. Notice that James, Sam & Roger are all still expanded!

So the question is... how to reset the whole dang thing so that it forgets everything?
For step 5, I would expect that a Rebind alone would reset enough that the new root would have an expand option.
But in step 8, the items are still expanded!!
They do have the same key, so I can understand how it remembers, but not why!
And the fact that I called CollapseAllItems makes it even more annoying.

Joel

<%@ Page Language="C#" Layout="Standard" Title="Organizational Chart" EnableViewState="true" %>
<script language="C#" runat="server">
/*
var _data = new[] {
        new { id = 1, supervisor = 0, name = "Dave" },
        new { id = 2, supervisor = 1, name = "James" },
        new { id = 3, supervisor = 2, name = "Sam" },
        new { id = 4, supervisor = 2, name = "Roger" },
        new { id = 5, supervisor = 1, name = "Ken" }
    };
 
 */
 
private void rblChartSelector_SelectedIndexChanged(object sender, EventArgs args)
{
    if (rblChartSelector.SelectedValue == "C") tlOrgChart.CollapseAllItems();
    tlOrgChart.Rebind();
}
 
private void tlOrgChart_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs args)
{
    switch (rblChartSelector.SelectedValue)
    {
        case "A":
            tlOrgChart.DataSource = new[] {
                new { id = 2, supervisor = 1, name = "James" },
            };
            break;
        case "B":
        case "C":
            tlOrgChart.DataSource = new[] {
                new { id = 1, supervisor = 0, name = "Dave" },
            };
            break;
    }
}
 
protected void tlOrgChart_ChildItemsDataBind(object sender, TreeListChildItemsDataBindEventArgs args)
{
    switch ((int)args.ParentDataKeyValues["id"])
    {
        case 1:
            args.ChildItemsDataSource = new[] {
                new { id = 2, supervisor = 1, name = "James" },
                new { id = 5, supervisor = 1, name = "Ken" }
            };
            break;
        case 2:
            args.ChildItemsDataSource = new[] {
                new { id = 3, supervisor = 2, name = "Sam" },
                new { id = 4, supervisor = 2, name = "Roger" },
            };
            break;
        default:
            args.ChildItemsDataSource = new DataTable();
            break;
    }
}
 
</script>
 
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
 
<asp:PlaceHolder ID="phChartSelector" runat="server">
    <asp:RadioButtonList runat="server" ID="rblChartSelector" OnSelectedIndexChanged="rblChartSelector_SelectedIndexChanged" AutoPostBack="true">
        <asp:ListItem Text="A: James (Second Level Node)" Value="A" Selected="True" />
        <asp:ListItem Text="B: Dave (Top Level Node)" Value="B" />
        <asp:ListItem Text="C: Dave (Top Level Node, With Collapse)" Value="C" />
    </asp:RadioButtonList>
</asp:PlaceHolder>
 
<TELERIK:RadTreeList ID="tlOrgChart" runat="server" OnNeedDataSource="tlOrgChart_NeedDataSource"
    AutoGenerateColumns="false" DataKeyNames="id" ParentDataKeyNames="supervisor"
    OnChildItemsDataBind="tlOrgChart_ChildItemsDataBind" AllowLoadOnDemand="true"
    NoRecordsText="There is no data available.">
    <Columns>
        <TELERIK:TreeListBoundColumn DataField="name" />
    </Columns>
</TELERIK:RadTreeList>
 
</asp:Content>
0
Kostadin
Telerik team
answered on 31 Jul 2013, 10:45 AM
Hi Joel,

Actually this is expected because you could not change the TreeList structure except if you are not creating it progammatically. I would recommend you to examine the following help article which demonstrates how to define the TreeList programmatically. Additionally you could check out the following help topic which demonstrates how to change the structure dynamically of RadGrid. The approach is the same for TreeList as well.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
TreeList
Asked by
Joel Kraft
Top achievements
Rank 2
Answers by
Kostadin
Telerik team
Joel Kraft
Top achievements
Rank 2
Share this question
or