1

I have a treeView with ShowAllCheckBox property to true, I need to bind a javascript function to each checkbox on their click event.

How to do this can any one suggest ?

2 Answers 2

1

Using Jquery, you can easily do it as follows

$("#TreeView1 input[type='checkbox']").bind('click',function(){
            var ischecked = (this.checked == true);
            alert(ischecked);
         });
Sign up to request clarification or add additional context in comments.

Comments

0

You can't do it server side w/o re-parsing render output. TreeView does not use Controls collection and renders input elements directly.

You'd have to resort to some form of java script as suggested by gk or traditionally:

<script type="text/javascript" language="javascript">
    var inputs = document.getElementsByTagName("input");
    for (i = 0; i < inputs.length; i++)
        if (inputs[i].type == "checkbox" && inputs[i].name.indexOf("TreeView1", 0) == 0)
            inputs[i].onclick = function() { alert('click'); };
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.