0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.