views:

184

answers:

2

My code is :

            <asp:TreeView ID="TreeViewCategories" runat="server" ExpandDepth="0" Style="min-height: 200px;
                max-height: 500px;" LineImagesFolder="~/TreeLineImages" 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" SelectAction="Expand" PopulateOnDemand="True" Value="All Items" />
                </Nodes>
            </asp:TreeView>

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

so I see (with firebug) for my selected node appears Visited style , node style , leaf style but not Selected node style :(

How to fix this HTML/CSS/ASP to make selected node Bold and Blue for example ?

Thank you.

added : adding nodes like here :

            foreach(c : Category in rootCategories)
            {
                mutable newNode : TreeNode = TreeNode(c.Title, c.Id);
                newNode.SelectAction = TreeNodeSelectAction.SelectExpand;
                newNode.NavigateUrl = "Items.aspx?catId=" + c.Id.ToString() + "&lvl=0";

solved with...

categoryId : string = Request.QueryString["catId"];
n : TreeNode = findNode(categoryId, TreeViewCategories.Nodes, lvl);
n.Selected = true;
A: 

In your CSS, replace

a.SelectedNodeStyle { background:#6799D1; color:#6799D1; display:block; padding:2px 0 2px 3px; }

with

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

And in your ASPX, replace

SelectedNodeStyle-ForeColor="RoyalBlue"

with

SelectedNodeStyle-CssClass="SelectedNodeStyle"
Doesn't helps ...
nCdy
Do your items have a NavigateURL?
SteveCav
@nCdy, Firebug should show something like `class="TreeViewCategories_0 NodeStyle TreeViewCategories_1 LeafNodesStyle TreeViewCategories_7 SelectedNodeStyle TreeViewCategories_9"` on the selection. Not seeing it?
can't see SelectedNodeStyle on Firebug :( And yes - my items have a NavigateURL.
nCdy
+1  A: 

The SelectAction attribute on the asp:TreeNode is Expand change it to SelectExpand.

This ensures that there is a postback and the tree control is redrawn to apply the seleceted node style that you set on the treeview

<asp:TreeView ID="TreeViewCategories" runat="server" ExpandDepth="0" Style="min-height: 200px;
        max-height: 500px;" LineImagesFolder="~/TreeLineImages" 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" SelectAction="SelectExpand" Value="All Items">
                <asp:TreeNode Text="All Items" SelectAction="SelectExpand" Value="All Items" />
                <asp:TreeNode Text="All Items" SelectAction="SelectExpand" Value="All Items" />
                <asp:TreeNode Text="All Items" SelectAction="SelectExpand" Value="All Items" />
            </asp:TreeNode>
        </Nodes>
    </asp:TreeView>
Vinay B R
Thank you , but it doesn't helped . . . :( maybe becuase of NavigateURL on nodes ?
nCdy
even if I do <asp:TreeNode Text="All Items" Selected="true" SelectAction="SelectExpand" PopulateOnDemand="True" Value="All Items" /> it doesn't appears :(
nCdy
Not sure why it doesnt work for you, i tested it out by adding some nodes directly in the markup. I am editing my answer to add the mark up
Vinay B R
ok ... I'll try again and again )
nCdy
But they doesn't work with Navigate ...
nCdy
ok... since u have a navigation url specified, on selecting a node you will be redirected to that page (items.aspx) so how do you expect the tree to persist selected node. Can you explain a bit more on what you are trying to implement, we might be able to come up with something which might not require specifying a navigation url
Vinay B R
I'm so stupid ^____^ but , finally it solved. Topic changed
nCdy