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

How I Can set SelectedNode.Value From Client Side

1 Answer 147 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ahmad Alkhiary
Top achievements
Rank 1
Ahmad Alkhiary asked on 01 Dec 2008, 05:24 PM

Dear Telerik Team,

Please my problem is how I can set the (SelectedNode.Value) from Client side so it will show the node text in the ComboBox text property.
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 a JavaScript function to accomplish that (FindNode) and I added an input field to use it for passing the value (ID=SelectedValue) but it's not working with me or May I did not write it the correct way.

I hope I get your response soon.

Thank you

My User Control ASPX File Code:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MenuOptionsTree.ascx.vb" Inherits="TerelikCompoTree.MenuOptionsTree" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" dir=rtl>   
 <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 FindNode()
    {      
        var comboBox = $find("<%= RadComboBox1.ClientID %>");
        var treevw = comboBox.get_items().getItem(0).findControl("RadTreeView1");          
        var node = treevw.findNodeByValue(SelectedValue.value);
        node.select()
       
        comboBox.set_text(node.get_text());

        comboBox.trackChanges();
        comboBox.get_items().getItem(0).set_value(node.get_text());
        comboBox.commitChanges();
    }
   
    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="124" runat="server" enableviewstate="true" type="hidden" />
</body>

Thank you

1 Answer, 1 is accepted

Sort by
0
Dimitar Milushev
Telerik team
answered on 02 Dec 2008, 06:10 AM
Hello Ahmad Alkhiary,

You can replace the two calls to node.get_text() in the nodeClicking handler with calls to node.get_value() to achieve this. You should also set OnClientLoad="comboLoad" to the ComboBox so the comboLoad method is properly called in order to set the ComboBox text on postback.

I hope this helps.

Best wishes,
Dimitar Milushev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Ahmad Alkhiary
Top achievements
Rank 1
Answers by
Dimitar Milushev
Telerik team
Share this question
or