Treeview in combobox - How to get ID

6 posts, 1 answers
  1. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 13 Jan 2010 Link to this post

    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

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1549 posts
    Member since:
    Sep 2012

    Posted 14 Jan 2010 Link to this post

    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.

  3. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 14 Jan 2010 Link to this post

    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

  4. Yana
    Admin
    Yana avatar
    4338 posts
    Member since:
    Sep 2012

    Posted 18 Jan 2010 Link to this post

    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.

  5. Andy Green
    Andy Green avatar
    120 posts
    Member since:
    Jul 2009

    Posted 18 Jan 2010 Link to this post

    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

  6. Answer
    Yana
    Admin
    Yana avatar
    4338 posts
    Member since:
    Sep 2012

    Posted 19 Jan 2010 Link to this post

    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.

Back to Top