Databind radtree Template on drag drop

2 posts, 0 answers
  1. Håkon
    Håkon avatar
    1 posts
    Member since:
    Feb 2008

    Posted 30 Sep 2010 Link to this post

    Hi
    I have a SharePoint web part with a radtreeview control using template. On drag Drop the template no longer databind the node in the TextBoxTemplate class.
    The node loses text after second drag drop if i use template, when i don't use template evrything work fine.
    The treeview datasours is a <List> object that i generated from a sharepoint list.
    I think it is a data bind error.

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        AppID = this.ClientID.ToString() + this.ClientIDSeparator.ToString();
        Page.ClientScript.RegisterStartupScript(typeof(_BUV2), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);
        if (this.Page.Form != null)
        {
            string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
            if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
            {
                this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
            }
        }
        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
        if (scriptManager == null)
        {
            scriptManager = new RadScriptManager();
            this.Page.Form.Controls.AddAt(0, scriptManager);
        }                        
    }
      
    protected override void OnLoad(EventArgs e)
    {            
        try
        {
            //Panel panel = new Panel();
            Panel panel = new Panel();
            panel.ID = "panel";
            this.Controls.Add(panel);
            HenteNoder();//Create <List> of Object
            treeView1 = new RadTreeView();
            treeView1.ID = "treeView1";
            treeView1.DataTextField = "Tittel";
            treeView1.DataValueField = "ID";
            treeView1.DataFieldID = "ID";
            treeView1.DataFieldParentID = "Parent";
            treeView1.DataSource = List_treeView1;
            treeView1.NodeTemplate = new TextBoxTemplate();
            treeView1.DataBind();
            treeView1.ExpandAllNodes();// = treeView1;
            treeView1.Nodes[0].AllowDrag = false;
            treeView1.EnableDragAndDrop = true;
            treeView1.NodeDrop += new RadTreeViewDragDropEventHandler(TreeDrop);
            panel.Controls.Add(treeView1);
      
            RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
            if (ajaxManager == null)
            {
                ajaxManager = new RadAjaxManager();
                ajaxManager.ID = "RadAjaxManager1";
                Controls.Add(ajaxManager);
                this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager);
                this.Page.Form.Controls.Add(ajaxManager);
            }
            ajaxManager.AjaxSettings.AddAjaxSetting(treeView1, panel, null);
        }
        catch
        {
        }
    }
      
    protected void TreeDrop(object sender, RadTreeNodeDragDropEventArgs NodeEvent)

        RadTreeNode destNode = NodeEvent.DestDragNode;
        string result = string.Empty;
        string DesRoot = destNode.TreeView.ID.ToString().Remove(0, 3);
        if (NodeEvent.DraggedNodes.Count > 0)
        {
            foreach (RadTreeNode node in NodeEvent.DraggedNodes)
            {
                if (node != destNode.Parent)
                {
                    RadTreeNodeCollection nodeCollection = (node.ParentNode != null) ? node.ParentNode.Nodes : node.TreeView.Nodes;
                    nodeCollection.Remove(node);
                    node.ContextMenuID = destNode.ContextMenuID;
                    destNode.Nodes.Add(node); 
                }
                node.Selected = false;
            }
        }
        destNode.Expanded = true;
      
        //Save changes to sharepoint list
    }
      
    class TextBoxTemplate : ITemplate
    {            
        public void InstantiateIn(Control container)
        {
            Label label1 = new Label();
            label1.ID = "ItemLabel";
            label1.Text = "ERROR ERROR ERROR ERROR ERROR";
            label1.Font.Size = 10;
            label1.Font.Bold = true;
            label1.DataBinding += new EventHandler(label1_DataBinding);
            container.Controls.Add(label1);
        }
        private void label1_DataBinding(object sender, EventArgs e)
        {
            Label target = (Label)sender;
            RadTreeNode node = (RadTreeNode)target.BindingContainer;
            string nodeText = (string)DataBinder.Eval(node, "Text");
            target.Text = nodeText + "It works :)";
        }
    }
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 06 Oct 2010 Link to this post

    Hi Håkon,

    Can you try calling RadTreeView's DataBind() method at the end of the TreeDrop handler? Does this help?


    Greetings,
    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top