Thomas
Thomas

Reputation: 34188

How to attach javascript with treeview node?

after populating treeview and i want to traverse in all the node and want to attach javascript if the node has child node. how to do it in asp.net when work with treeview control.

please help. thanks

Upvotes: 0

Views: 820

Answers (1)

volpav
volpav

Reputation: 5128

What do you mean by "attaching Javascript"? Do you want to override the behavior of the particular node when it's being clicked? Is so, try the following approach:

protected void Page_PreRender(object sender, EventArgs e)
{
    foreach (TreeNode rootNode in myTreeView.Nodes)
    {
        ExamineTreeNode(n);
    }
}

private void ExamineTreeNode(TreeNode n)
{
    if (n.ChildNodes.Count > 0)
    {
        n.NavigateUrl = "javascript:alert('Has children!')";
        foreach (TreeNode child in n.ChildNodes)
        {
            ExamineTreeNode(child);
        }
    }
}

Hope this is what you needed.

Upvotes: 1

Related Questions