views:

1666

answers:

3

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 ?

+1  A: 

Using Jquery, you can easily do it as follows

$("#TreeView1 input[type='checkbox']").bind('click',function(){
            var ischecked = (this.checked == true);
            alert(ischecked);
         });
gk
A: 

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>
Ruslan
A: 

Hey Ruslan, Where do you put this script in the .aspx file? and how you can tell the TreeView to apply this script?

Use a comment next time instead of an answer (or just ask a new question)
ripper234