Usman
Usman

Reputation: 3278

Add onclick event on treeview Nodes and Child Node using Jquery

i have an ASP tree view having a Node

enter image description here

so now, i have to add a click event on NODE (i.e Accomodations) that is different from the click event on Child Node(i.e Blue Parrot INN etc.)

How i achieve this??

any help will greatly appreciated...

NOTE: I want to achieve this using jquery

Upvotes: 1

Views: 9396

Answers (2)

Usman
Usman

Reputation: 3278

I add CSSclass on Root, Parent and Leaf Node like

    RootNodeStyle-CssClass="RootNodeStyle"
    ParentNodeStyle-CssClass="ParentNodeStyle"
    LeafNodeStyle-CssClass="LeafNodeStyle"

and then in js i write jquery as follow

   $("RootNodeStyle").click(function(){
        alert("Root Node is click");
   });

   $("ParentNodeStyle").click(function(){
        alert("Parent Node is click");
   });

   $("LeafNodeStyle").click(function(){
        alert("Leaf Node is click");
   });

This way i achieved what i want to get.... :)

Upvotes: 1

sevenkul
sevenkul

Reputation: 966

ASP.NET assigns some predictable client id's to the nodes. Using these client id's, you can assign click event with jquery.

$(document).ready(function () {
    $("#id_of_your_node_in_html_page").click(function () {
        //do something
    });
});

More to say:

So how to get the client id of the node? Let's say your tree view has server id as my_tree. Then client id of the nodes will be like the following:

Accomodations     my_treet0
    PIER HOUSE... my_treet1
    BLUE PARROT.. my_treet2
    ISLAND CITY.. my_treet3
Hotels            my_treet4
    COUNTRY...... my_treet5

Note the t and the increasing number. However this method is not reliable. Once you add or remove one child node, client id of subsequent nodes will change.

Alternative:

Here is a more reliable method for getting client id. Instead of Accomodations, write <a id='nodeAccomodations'>Accomodations</a> for the text property of the node. Then you can use nodeAccomodations as client id.

Upvotes: 0

Related Questions