How to get selected values using server side code?

6 posts, 0 answers
  1. Tao
    Tao avatar
    13 posts
    Member since:
    Jun 2012

    Posted 03 Jan 2014 Link to this post

    Hi, 
     I'm expecting something like raddropdowntree.selectedvalues or similar, but I couldn't find one. And also,is there any way to add items just like regular dropdown, like raddropdowntree.items.add()?

    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Jan 2014 Link to this post

    Hi,

    Please have a look into the following code snippet to get the selectedvalue of RadDropDownTree from the server side and add a new node to the RadDropDownTree. 

    ASPX:
    <telerik:RadDropDownTree ID="RadDropDownTree1" runat="server" DataFieldID="id" DataFieldParentID="parentid"
        DataTextField="text" DataSourceID="SqlDataSource1" DefaultMessage="Please select">
    </telerik:RadDropDownTree>
    <telerik:RadButton ID="RadButton1" runat="server" Text="GetSelectedItem" OnClick="RadButton1_Click">
    </telerik:RadButton>
    <asp:Label ID="label1" runat="server">
    </asp:Label>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        label1.Text = RadDropDownTree1.SelectedText;
        RadTreeNode node = new RadTreeNode();
        node.Text = "demo";
        RadDropDownTree1.EmbeddedTree.Nodes.FindNodeByText(label1.Text).InsertAfter(node);
    }

    Let me know if you have any concern.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tao
    Tao avatar
    13 posts
    Member since:
    Jun 2012

    Posted 06 Jan 2014 Link to this post

    Thank you, Shinu!

    The result is a string which includes the parent values and child values all together. Is there any way to output the result as a hierarchical structure or just output parent values and child values separately?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Jan 2014 Link to this post

    Hi,

    I guess you want to access the parent node and child nodes of a RadDropDownTree Separately. Please have a look into the following code snippet in which 'parent' array have all the ParentNodes of RadDropDownTree and 'child' array have all the ChildNodes.

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        string[] child =new string[50];
        string[] parent = new string[50];
        int i=0,j=0;
        foreach (RadTreeNode node in RadDropDownTree1.EmbeddedTree.Nodes)
        {
            parent[j] = node.Text;
            j++;
            if (node.GetAllNodes().Count!=0)
            {
                foreach (RadTreeNode subnode in node.GetAllNodes())
                {
                    child[i] = subnode.Text;
                    i++;
                }
            }
        }
    }

    Hope this will helps you.
    Thanks,
    Shinu.
  6. Tao
    Tao avatar
    13 posts
    Member since:
    Jun 2012

    Posted 16 Jan 2014 Link to this post

    Thank you, Shinu!

    It works for me. 
    Is it possible to traverse all the checked nodes and get their texts on client side?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Jan 2014 Link to this post

    Hi,

    Please have a look into the following code snippet to get the CheckedNodes text of RadDropDownTree on RadButton OnClientClicked event.

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked1(sender, args) {
            var dropdowntree = $find("<%=RadDropDownTree1.ClientID %>");
            var count = dropdowntree.get_embeddedTree().get_checkedNodes().length;
            for (var i = 0; i < count; i++) {
                alert(dropdowntree.get_embeddedTree().get_checkedNodes()[i].get_text());
            }
        }
    </script>

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017