Editing RadTreeNodes

4 posts, 0 answers
  1. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 08 Oct 2013 Link to this post

    I would like to edit RadTreeNodes in a RadWindow and after making changes, update RadTreeView according to those changes.
    The idea is to have a context menu with serveral options, one of them would be "Edit node". This action would open a RadWindow with information related to the node. The user would make changes and after changes are saved the treeview (just the treenode) would be updated.

    I have tried to implement that but i haven't been able to open a radwindow from context menu.
    Do you have an example on how to achieve that?
    Thank you,
    Sonia.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2013 Link to this post

    Hi Sonia,

    Please have a look into the full code that I tried to show a RadWindow on OnClientContextMenuItemClicked event.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuItemClicked="OnClientContextMenuItemClicked1">
        <ContextMenus>
            <telerik:RadTreeViewContextMenu ID="RadTreeViewContextMenu1" runat="server">
                <Items>
                    <telerik:RadMenuItem runat="server" Text="New">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem runat="server" Text="Edit">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadTreeViewContextMenu>
        </ContextMenus>
        <Nodes>
            <telerik:RadTreeNode runat="server" Text="OOPS" Value="1">
                <Nodes>
                    <telerik:RadTreeNode runat="server" Text="C++" Value="1.1">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode runat="server" Text="Java" Value="1.2">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
            <telerik:RadTreeNode runat="server" Text="MarkupLanguage" Value="2">
                <Nodes>
                    <telerik:RadTreeNode runat="server" Text="HTML" Value="2.1">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode runat="server" Text="XML" Value="2.2">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>
    <telerik:RadWindow ID="RadWindow1" runat="server">
        <ContentTemplate>
            <telerik:RadTextBox ID="RadTextBox1" runat="server">
            </telerik:RadTextBox>
        </ContentTemplate>
    </telerik:RadWindow>

    JavaScript:
    <script type="text/javascript">
        function OnClientContextMenuItemClicked1(sender, args) {
            if (args.get_menuItem()._text == "Edit") {
                var radwindow = $find('<%=RadWindow1.ClientID %>');
                radwindow.Show(true);
            }
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 08 Oct 2013 Link to this post

    Hi Princy,

    this is the piece of code for opening the window from the context menu,
    but how can i achieve to update content of the treeview according to changes made on radwindow?
    As i said i want to use radwindow to edit treenodes. I hope you can help me.

    Thanks,
    Sonia.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Oct 2013 Link to this post

    Hi Sonia,

    Please try the following JavaScript to set the TextBox Text as RadTreeNode Text in Edit Mode.

    JavaScript:
    function test() {
        var radwindow = $find('<%=RadWindow1.ClientID %>');
        var radtextbox = $find('<%=RadTextBox1.ClientID %>');
        var radtreeview = $find('<%=RadTreeView1.ClientID %>');
        value = radtextbox.get_value();
        var editednode = radtreeview.findNodeByText(node);
        editednode.startEdit();
        editednode.set_text(value);
        radtreeview.commitChanges();
        radwindow.hide();
    }

    Thanks,
    Princy.
Back to Top