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

How to get selected values using server side code?

5 Answers 604 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Tao
Top achievements
Rank 1
Tao asked on 03 Jan 2014, 11:24 PM
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!

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jan 2014, 05:10 AM
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.
0
Tao
Top achievements
Rank 1
answered on 06 Jan 2014, 07:17 PM
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?
0
Shinu
Top achievements
Rank 2
answered on 07 Jan 2014, 03:15 AM
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.
0
Tao
Top achievements
Rank 1
answered on 16 Jan 2014, 09:30 PM
Thank you, Shinu!

It works for me. 
Is it possible to traverse all the checked nodes and get their texts on client side?
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2014, 02:51 AM
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.
Tags
DropDownTree
Asked by
Tao
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tao
Top achievements
Rank 1
Share this question
or