Sandhurst
Sandhurst

Reputation:

Bind a Javascript function to TreeView CheckBox from ServerSide ASP.Net

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 ?

Upvotes: 1

Views: 4092

Answers (2)

Ruslan
Ruslan

Reputation: 1761

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>

Upvotes: 0

gk.
gk.

Reputation: 1262

Using Jquery, you can easily do it as follows

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

Upvotes: 1

Related Questions