Adding new items into a TreeView via a Window or Form

4 posts, 1 answers
  1. Tim
    Tim avatar
    15 posts
    Member since:
    Jul 2011

    Posted 06 Jul 2011 Link to this post

    Hi all,

    I've just started using the Telerik controls and I'm looking for some advice on how to achieve the requirement below.

    I'd like the user to be able to choose a 'Create' option from a context menu on a tree view node.

    On selecting this option, I'd like to display a Telerik Window to enable the user to create a new record. If this is too difficult, I'm happy for this to be some other UI element and I'm open to suggestion here.

    On saving the record, I'd like to add the newly created item into the tree node.

    1. Are there any code samples on how to open up a Window or form from a context menu item?

    2. I'm trying to figure out the code that's needed to add items into the treeview and I'm following the article beneath.

    http://www.telerik.com/help/aspnet-ajax/treeview-general-add-node-in-edit-mode-by-default.html

    When I add the following javascript into my page, I get the following error when loading the page.

    function HighlightNode(value) {
        var tree = $find("<%= RadTreeView1.ClientID %>");
        var node = tree.findNodeByValue(value);
        if (node != null) {
            node.startEdit();
        }
    }


    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    I’m not sure if this is relevant but I've added a RadAjaxManager onto my page and am using the code beneath in the AddNode method.
    Dim script As String = "HighlightNode(""" + newNode.Value + """)"
    RadAjaxManager1.ResponseScripts.Add(script)

    Any help or guidance would be much appreciated.

    Tim
  2. Tim
    Tim avatar
    15 posts
    Member since:
    Jul 2011

    Posted 07 Jul 2011 Link to this post

    As I've not had any reply to this, am I trying to do something beyond what the TreeView was originally designed to do?

    Since these controls are new to me, I don't fully understand their capabilities and whether or not I'm being too optimistic with my expectations. If what I'm doing here is technically too difficult, I'd appreciate it if someone could tell me in order to save me from wasting too much time.

    In the meantime, I've started looking at the TreeList control to see whether or not I can achieve my requirements easier using that control. I'm struggling a bit with the issue beneath and would be grateful if anyone knows the answer.

    http://www.telerik.com/community/forums/aspnet-ajax/treelist/how-to-use-different-templates-for-adding-editing-nodes.aspx

    Many thanks,
    Tim
  3. Answer
    Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 08 Jul 2011 Link to this post

    Hello Tim,

    The error that you got is well known - all you need to do is to add RadCodeBlock as shown:
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                //Put your JavaScript code here.
            </script>
        </telerik:RadCodeBlock>

    As for the question about adding new node, we recommend doing this inline in the RadTreeView like in our Context Menu demo.

    Hope this will help you.

    All the best,
    Plamen Zdravkov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  4. Tim
    Tim avatar
    15 posts
    Member since:
    Jul 2011

    Posted 08 Jul 2011 Link to this post

    Thanks Plamen
Back to Top