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

Setting The SelectNode.Value From Code-Behind File

2 Answers 166 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ahmad Alkhiary
Top achievements
Rank 1
Ahmad Alkhiary asked on 29 Nov 2008, 01:41 PM
Dera Telerik Support,

How can I set the SelectedNode.Value in the TreeView control which is inside the ComboBox Item Template from code behind file so it will show the node text in the ComboBox.

In code behind I'm retrieving the data from the database and move it to the corresponding controls on the page and everything fine except the ComboBox. It may need passing a value to JavaScript function from code behind which will do the rest of the job.

I added the following JavaScript function trying to accomplish the behavior


function selectNode(SelectedValue)
{
    if (SelectedValue != null)
    {
       var treevw = $find("<%= RadTreeView1.ClientID %>");
       var node = treevw.findNodeByValue(SelectedValue);
       node.select();

       var comboBox = $find("<%= RadComboBox1.ClientID %>");
       comboBox.set_text(node.get_text());
   }
}


But it produce the following error

 

Compiler Error Message: BC30451: Name 'RadTreeView1' is not declared.

Source Error:

Line 31:        if (SelectedValue != null)
Line 32:        {
Line 33: var treevw = $find("<%= RadTreeView1.ClientID %>");Line 34:         var node = tree.findNodeByValue(SelectedValue);
Line 35:         node.select();

The following the ASPX page Code:

<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" dir=rtl>
    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    </asp:ScriptManagerProxy>
 <script type="text/javascript">         
    function comboLoad(sender, eventArgs)
    {
        sender.set_text(sender.get_items().getItem(0).get_value());
    }

    function nodeClicking(sender, args)
    {
        var comboBox = $find("<%= RadComboBox1.ClientID %>");
        var node = args.get_node()
      
        document.getElementById('<%=NodeValue.ClientID%>').value = node.get_value();

        comboBox.set_text(node.get_text());
      

        comboBox.trackChanges();
        comboBox.get_items().getItem(0).set_value(node.get_text());
        comboBox.commitChanges();

        comboBox.hideDropDown();
    }

    function selectNode(SelectedValue)
    {
       if (SelectedValue != null)
       {
        var treevw = $find("<%= RadTreeView1.ClientID %>");
        var node = treevw.findNodeByValue(SelectedValue);
        node.select();
       
        var comboBox = $find("<%= RadComboBox1.ClientID %>");       
        comboBox.set_text(node.get_text());
       }       
    }

    function StopPropagation(e)
    {
        if(!e)
        {
            e = window.event;
        }

        e.cancelBubble = true;
    }
   
    function OnClientDropDownOpenedHandler(sender, eventArgs)
    {
        var tree = sender.get_items().getItem(0).findControl("RadTreeView1");
        var selectedNode = tree.get_selectedNode();
        if (selectedNode)
        {
            selectedNode.scrollIntoView();
        }
    }
  
</script>
<telerik:RadComboBox ID="RadComboBox1" Runat="server" Height="200px"
    Skin="Sunset" Width="348px">
    <ItemTemplate>
      <div ID="TreeDiv" onclick="StopPropagation(event)" dir=rtl>
        <telerik:RadTreeView
         ID="RadTreeView1"
         Runat="server"
         Height="350px"
         Width="100%"
         OnClientNodeClicking="nodeClicking" Skin="Sunset">
            <CollapseAnimation Duration="100" Type="OutQuint" />
            <ExpandAnimation Duration="100" />
        </telerik:RadTreeView>
        </div>
    </ItemTemplate>
    <Items>
      <telerik:RadComboBoxItem Text="" />
    </Items>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:RadComboBox>
<input id="NodeValue" value="0" runat="server" enableviewstate="true" type="hidden" />
<input id="SelectedValue" value="0" runat="server" enableviewstate="true" type="hidden" /> 
</body>

Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 02 Dec 2008, 12:48 PM
Hello Ahmad Alkhiary,

You are not getting the proper reference to the treeview object.

Please check our online example and help article on how to do this.

I hope this helps.

Kind regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Web Services
Top achievements
Rank 2
answered on 31 Jul 2009, 07:36 PM
Thanks, the second link helped me with a similar problem.
Tags
ComboBox
Asked by
Ahmad Alkhiary
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Web Services
Top achievements
Rank 2
Share this question
or