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

Adding new items into a TreeView via a Window or Form

3 Answers 50 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 06 Jul 2011, 11:38 AM
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

3 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 07 Jul 2011, 05:00 PM
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
0
Accepted
Plamen
Telerik team
answered on 08 Jul 2011, 02:38 PM
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!

0
Tim
Top achievements
Rank 1
answered on 08 Jul 2011, 03:47 PM
Thanks Plamen
Tags
TreeView
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or