开发者

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 he开发者_如何学编程lp. thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜