Custom Attributes on a RadTreeNode checkbox

4 posts, 1 answers
  1. Dave
    Dave avatar
    3 posts
    Member since:
    Jun 2011

    Posted 28 Jun 2011 Link to this post

    I've been searching around and I can't find anything pointing me in the right direction to do this. I need to add a custom attribute to each checkbox associated with a RadTreeNode inside of a RadTreeView. Not every node is checkable, but for the ones that are I need to figure out a way to add a custom attribute to those checkboxes. Does anyone have any suggestions?

    Let me know if you need more info to help me out.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jun 2011 Link to this post

    Hello Dave,

    Try the following client side code in pageLoad.

    Javascript:
    <script type="text/javascript">
        function pageLoad()
        {
            var treeview = $find("<%= RadTreeView1.ClientID %>");
            var i;
            for (i = 0; i < treeview.get_allNodes().length; i++)
           {
                var currentNode = treeview.get_allNodes()[i];
                var checkBoxElement = currentNode.get_checkBoxElement();//accessing the checkbox
                checkBoxElement.setAttribute("NewAttribute", " AttributeValue");//adding custom attribute.
                alert(checkBoxElement.getAttribute("NewAttribute"));
           }
        }
    </script>

    Thanks,
    Princy.
  3. Answer
    Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 29 Jun 2011 Link to this post

    Hello Princy,

    That should be the way!
    I would only correct it to cache what's gathered by get_allNodes function, something like the following:
    function pageLoad()
    {
        var treeview = $find("<%= RadTreeView1.ClientID %>");
        var allNodes = treeview.get_allNodes();
        for (var i = 0; i < allNodes.length; i++)
       {
            var currentNode = allNodes[i];
            var checkBoxElement = currentNode.get_checkBoxElement();//accessing the checkbox
            checkBoxElement.setAttribute("NewAttribute", " AttributeValue");//adding custom attribute.
            alert(checkBoxElement.getAttribute("NewAttribute"));
       }
    }


    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  4. Dave
    Dave avatar
    3 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Thanks a ton! That worked perfectly.

    I was trying to do all of that from the code-behind initially and just kept hitting into walls.
Back to Top