TreeView with Load on Demand loses text after Drag and Drop

5 posts, 0 answers
  1. Liz
    Liz avatar
    4 posts
    Member since:
    Mar 2013

    Posted 26 Mar 2013 Link to this post

    Hello,

    I am currently using a RadTreeView that loads its child nodes on demand.

    When a node is dragged and dropped (using server side code) onto a child node (that was loaded on demand), an Ajax postback occurs and the expanded child nodes, including the dropped node display with no text. The structure and icons appear correctly but the node text no longer displays.

    If an additional postback occurs (through another drag and drop or some other action), the text re-appears.

    Please advise.


    Very Respectfully,
    Liz
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 29 Mar 2013 Link to this post

    Hello Liz,

    In case of using node templates for customizing your RadTreeView control, I would suggest data-binding both destination and source node in your NodeDrop server-side event handler.
    If you are adding your templates at run-time, please instantiate your template and apply it to both nodes in that same event handler.

    If you are still facing that issue, please elaborate a bit more on your scenario or open a support ticket in order to sends us a runnable project for further investigation. 

    Kind regards,
    Boyan Dimitrov
    the Telerik team
    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 their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Liz
    Liz avatar
    4 posts
    Member since:
    Mar 2013

    Posted 15 Apr 2013 Link to this post

    Hi Boyan,

    I am just coming back to this problem now. Sorry for the delay.

    Is there any chance you could post an example of what you mean for data-binding the nodes? I have the tree data-bound, but I am not certain what you mean when you say to data-bind a single node.

    Very Respectfully,
    Liz
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 17 Apr 2013 Link to this post

    Hello Liz,

    Thank you for getting back to us.

    The code snippet below illustrates how you can data bind the source node and your destination node in your NodeDrop server-side event:
    //markup code
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnNodeExpand="RadTreeView1_NodeExpand" EnableDragAndDrop="true" EnableDragAndDropBetweenNodes="true" OnNodeDrop="RadTreeView1_NodeDrop">      
        .....
    </telerik:RadTreeView>
    //code behind
    protected void RadTreeView1_NodeDrop(object sender, RadTreeNodeDragDropEventArgs e)
        {
            e.DestDragNode.Nodes.Add(e.SourceDragNode);
            e.DestDragNode.Expanded = true;
            e.DestDragNode.DataBind();
            e.SourceDragNode.DataBind();    
        }

    If this is not solving your issue, could you please clarify the following;
    • How do you load your nodes?
    • How do you apply your templates?
    • How do you add the source node to the destination node in the code behind?

    Hope that this will be helpful.

    All the best,
    Boyan Dimitrov
    the Telerik team
    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 their blog feed now.
  6. Liz
    Liz avatar
    4 posts
    Member since:
    Mar 2013

    Posted 01 May 2013 Link to this post

    Fixed the problem.

    I had to loop back over the nodes in PostBack and re-apply the NodeTemplate. On its own, this caused node data to be wonky (node value mismatched with positions), but after applying DataBinding as well, the issue was resolved.

    I'm not sure it's the best way to do it, but I've included an example of what worked for me below:

    protected void Page_Load(object sender, EventArgs e)
    {
       if (Page.IsPostBack)
       {
          CustomTemplate radTreeTemplate = _radTree.NodeTemplate == null ? new CustomTemplate() : _radTree.NodeTemplate as CustomTemplate;
     
          IList<RadTreeNode> treeNodes = _radTree.GetAllNodes();
          foreach (RadTreeNode node in treeNodes)
          {
               radTreeTemplate.InstantiateIn(node);
               node.DataBind();
          }
          ....
       }
       ...
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017