树视图在检查节点后更改位置

本文关键字:位置 节点 视图 检查 | 更新日期: 2023-09-27 18:32:21

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

那是更新面板中的树

<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
        }
    }

提前致谢

树视图在检查节点后更改位置

这个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) {
            }
        }