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

Treeview in combobox - How to get ID

5 Answers 214 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 1
Andy Green asked on 13 Jan 2010, 09:27 AM
Hi

In this example:
http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/treeviewcombobox/defaultcs.aspx?product=treeview

When you hit submit the text value is sent back, how do I get the ID of the treeview node into the ID of the combo box.

I need the ID of the tree view node when I send the page to the server.

I have code that does this on postback, but I'd like to do it client side if possible.

Andy

5 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 14 Jan 2010, 03:42 PM
Hi Andy Green,

The RadTreeNode class does not have property called ID. This is to indicate that the nodes don't have ids by default. Why do you need the ID? Isn't the value or the text enough to determine which node was clicked?

All the best,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Andy Green
Top achievements
Rank 1
answered on 14 Jan 2010, 03:49 PM
Hi

I'm using this code to populate the treeview with data, and assigning each node the id from the database corressponding to the value - they are name:value pairs.
 Dim c As New JobPlan  
            Dim c_dt As DataTable = c.CategoryTreeByService(Service_ID)  
 
            If c_dt.Rows.Count > 0 Then  
                Dim rtvCategories As RadTreeView = CType(Page.Master.FindControl("ctl00$cphContent$txtCategory$i0$rtvCategory"), RadTreeView)  
                With rtvCategories  
                    .DataValueField = 1 
                    .DataSource = c_dt 
                    .DataFieldID = "Category_ID" 
                    .DataFieldParentID = "ParentCategory_ID" 
                    .DataTextField = "Category" 
                    .DataValueField = "Category_ID" 
                    .DataBind()  
                    '.ExpandAllNodes()  
                End With  
            End If 

When I click on the node, the text value is placed in the radcombo box , I need the ID field so that when I save to the database its the ID field that gets saved back.

Andy
0
Yana
Telerik team
answered on 18 Jan 2010, 12:57 PM
Hello Andy,

I see in the example code that you set  "Category_ID"  also to the Value of the nodes (DataValueField). The other option is to set it to a custom attribute in NodeDataBound event and then use this attribute to receive it when needed.

All the best,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Andy Green
Top achievements
Rank 1
answered on 18 Jan 2010, 01:44 PM
Hi

I'm still not sure yo get what I mean, I can get the value of the node server side with e.Node.Value cant I.

What I need is this value passed into the radcombobox Client Side. The example you give only passes the text value from the treeview with:
function nodeClicking(sender, args)  
            {  
                var comboBox = $find("<%= RadComboBox1.ClientID %>");  
 
                var node = args.get_node()  
 
                comboBox.set_text(node.get_text());  
 
                comboBox.trackChanges();  
                comboBox.get_items().getItem(0).set_value(node.get_text());  
                comboBox.commitChanges();  
 
                comboBox.hideDropDown();  
            }  
 
How can I also get the ID or are you saying that there is no NOde id on the client, in which case how do you get it on the server.

Thanks for your help.

Andy
0
Accepted
Yana
Telerik team
answered on 19 Jan 2010, 12:51 PM
Hi Andy,

I'm sorry for not being clear enough.

Please modify nodeClicking method like this:

<script type="text/javascript">
    function nodeClicking(sender, args) {
        var comboBox = $find("<%= RadComboBox1.ClientID %>");
 
        var node = args.get_node()
 
        comboBox.set_text(node.get_text());
 
        comboBox.trackChanges();
        comboBox.get_items().getItem(0).set_value(node.get_text());
        comboBox.get_items().getItem(0).get_attributes().setAttribute("nodeValue", node.get_value());
        comboBox.commitChanges();
 
        comboBox.hideDropDown();
    
 
</script>

then you can get the value of the selected node in code-behind like this:

Dim val as String = RadComboBox1.Items(0).Attributes("nodeValue")

Regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Andy Green
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Andy Green
Top achievements
Rank 1
Yana
Telerik team
Share this question
or