1

我有一个 asp.net 树视图。在展开的节点上,我正在为展开的节点绑定子节点。但是如果我检查节点而不是展开它,节点和它的所有子节点都会改变位置并变得像主节点的子节点。再次单击 + 时,它会出现在正确的位置。任何想法如何解决它!

那是 updatePanel 中的树

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:TreeView ID="MyTreeView" runat="server" ImageSet="XPFileExplorer" NodeIndent="15"
    OnTreeNodeExpanded="MyTreeView_TreeNodeExpanded">
    <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
    <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
        NodeSpacing="0px" VerticalPadding="2px" />
    <ParentNodeStyle Font-Bold="False" />
    <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
        VerticalPadding="0px" />
</asp:TreeView>

        </ContentTemplate>
</asp:UpdatePanel>

从后面的代码:在页面加载时我有:

if (!this.IsPostBack)
            {
                this.MyTreeView.ShowCheckBoxes = TreeNodeTypes.All;
                this.MyTreeView.ShowLines = true;
                FillTree();//custom method just to fill the tree
            }

    protected void MyTreeView_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
        TreeNode expandedNode = e.Node;

        if (expandedNode.Value != "-1" && expandedNode.Value == "-2")
        {
            //Some logic
        }

    }

提前致谢

4

1 回答 1

0

这个 JavaScript 函数修复了树:

function FixTreeview(treeView) {
            try {
                if (treeView) {
                    var treeLinks = treeView.getElementsByTagName("a");
                    var nodeCount = treeLinks.length;
                    for (i = 0; i < nodeCount; i++) {
                        if (treeLinks[i].firstChild.tagName) {
                            if (treeLinks[i].firstChild.tagName.toLowerCase() == "img") {
                                var currentToggleLink = treeLinks[i];
                                var childContainer = GetParentByTagName("table", currentToggleLink).nextSibling;
                                try {
                                    eval(currentToggleLink.href);
                                } catch (e) {
                                }
                            }
                        }
                    } 
                }
            } catch (e) {
            }
        }
于 2012-12-05T09:15:20.990 回答