Select RadTree Item in radComboBox by JavaScript

3 posts, 1 answers
  1. kia
    kia avatar
    17 posts
    Member since:
    Oct 2010

    Posted 05 Mar 2014 Link to this post

    Hi
    I have a RadComboBox with a radTree in it.
    I have get text and value of tree node from DataBase. Now i want to select item of radTree that equal to value by JavaScript.
    How can i do it?

    Here is definition of RadComboBox:

    <telerik:RadComboBox runat="server" ID="cmb" EnableVirtualScrolling="true"
        Height="140px" ShowToggleImage="True" Style="vertical-align: middle;" Width="100%"
        OnClientDropDownOpened="cmb_ClientOpened">
        <ItemTemplate>
            <telerik:RadTreeView ID="tv" runat="server" OnClientNodeClicking="tv_ClientNodeClicking">
            </telerik:RadTreeView>
        </ItemTemplate>
        <Items>
            <telerik:RadComboBoxItem Text="" />
        </Items>
    </telerik:RadComboBox>
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Mar 2014 in reply to kia Link to this post

    Hi kia,

    Please try the following JavaScript to access the RadTreeView inside the RadComboBox.

    JavaScript:
    var Combo = $find("<%=cmb.ClientID %>");//acceessing combobox clientside object
    var Tree = $telerik.findControl(Combo.get_element().parentNode, "tv");//accessing treeview clientside object
    alert(Tree.findNodeByValue("1").get_text());//find a node by value

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. kia
    kia avatar
    17 posts
    Member since:
    Oct 2010

    Posted 06 Mar 2014 in reply to Shinu Link to this post

    Thank you for your reply.
    I find tvNode by your code and finally select it.
    Here is complete code:
    var Combo = $find("<%=cmb.ClientID %>");
    var Tree = $telerik.findControl(Combo.get_element().parentNode, "tv");
     
    var tvNode = Tree.findNodeByValue(Value);
    tvNode.select();
    tvNode.set_selected(true);
    var parent = tvNode.get_parent();
    if (parent != null)
        parent.expand();
Back to Top