在母版页上导航Treeview时保持树视图的选定节点样式

时间:2011-11-09 10:41:37

标签: c# asp.net treeview

大家好我将selectednodestyle应用于树视图,当我不导航时,它可以正常工作。但在导航时,我无法看到树视图选定节点的应用颜色。这是我在母版页中的设计

<asp:TreeView ID="TreeViewCategories" runat="server" ExpandDepth="0" Style="min-height: 200px;
        max-height: 500px;" NodeIndent="0" LeafNodeStyle-CssClass="LeafNodesStyle" CssClass="TreeView"
        NodeStyle-CssClass="NodeStyle" ParentNodeStyle-CssClass="ParentNodeStyle" RootNodeStyle-CssClass="RootNodeStyle"
        SelectedNodeStyle-CssClass="SelectedNodeStyle" LeafNodeStyle-Width="100%" NodeStyle-Width="100%"
        ParentNodeStyle-Width="100%" RootNodeStyle-Width="100%" Font-Size="12pt">
        <Nodes>
            <asp:TreeNode Text="All Items" NavigateUrl="~/Default3.aspx" SelectAction="SelectExpand"
                Value="All Items">
                <asp:TreeNode Text="Hello" Value="Hello"></asp:TreeNode>
            </asp:TreeNode>
        </Nodes>
    </asp:TreeView>

这是我的css

<style type="text/css">
    .TreeView
    {
        border-bottom: 1px dotted #B2B2B2 !important;
    }
    .TreeView div
    {
        margin-left: 5px;
    }
    .TreeView table
    {
        border-top: 1px dotted #B2B2B2 !important;
    }
    .TreeView div table
    {
        border-bottom: none !important;
        border-top: none !important;
    }
    .TreeView table td
    {
        padding: 2px 0;
    }
    .LeafNodesStyle
    {
    }
    .RootNodeStyle
    {
    }
    /* ALL ELEMENTS */.NodeStyle
    {
    }
    .ParentNodeStyle
    {
        /*background:yellow;*/
    }
    .SelectedNodeStyle
    {
        font-weight: bold;
        color: #6799D1;
        display: block;
        padding: 2px 0 2px 3px;
    }
</style>

但导航到页面后我无法应用所选节点的颜色任何人都可以帮助我

1 个答案:

答案 0 :(得分:1)

你的代码工作正常,CSS也是如此。如果您注意到所选内容的文字变为粗体

如果您的基础是文本颜色的变化,则存在一些问题。如果您查看源代码,不仅 SelectedNodeStyle css样式应用于该项目,但这些也

NodeStyle FooterContent_TreeViewCategories_2 LeafNodesStyle FooterContent_TreeViewCategories_8 SelectedNodeStyle FooterContent_TreeViewCategories_10

所以我建议在你的css颜色上添加一些!重要的颜色变化才能生效。

.SelectedNodeStyle
{
    font-weight: bold;
    color: #6799D1 !important;
    display: block;
    padding: 2px 0 2px 3px;
}