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

Custom Attributes on a RadTreeNode checkbox

3 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 28 Jun 2011, 07:28 PM
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.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jun 2011, 12:36 PM
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.
0
Accepted
Nikolay Tsenkov
Telerik team
answered on 29 Jun 2011, 05:04 PM
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.

0
Dave
Top achievements
Rank 1
answered on 30 Jun 2011, 03:28 PM
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.
Tags
TreeView
Asked by
Dave
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nikolay Tsenkov
Telerik team
Dave
Top achievements
Rank 1
Share this question
or