asp.net - Change TreeView hover node style programmatically

TreeView hover node style
treeview server control made up of nodes. treeview HoverNodeStyle property control the appearance of a node when the mouse pointer is positioned (hover) on it. this property value can be set declaratively in the form Property-Subproperty such as HoverNodeStyle-ForeColor, HoverNodeStyle-BackColor, HoverNodeStyle-BorderColor etc. here Subproperty is a property of the TreeNodeStyle object.

we also can assign this property value programmatically in the form Property.Subproperty such as HoverNodeStyle.BackColor, HoverNodeStyle.BorderWidth, HoverNodeStyle.Font.Bold etc. so we can apply node hover style by changing it's text color, background color, font style, border style etc. the following c# example code demonstrate us how can we set treeview hover node styles programmatically at run time in asp.net.
TreeViewHoverNodeStyle.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if(!this.IsPostBack)
        {
            TreeView1.HoverNodeStyle.BackColor = Color.Crimson;
            TreeView1.HoverNodeStyle.ForeColor = Color.FloralWhite;
            TreeView1.HoverNodeStyle.BorderWidth = 1;
            TreeView1.HoverNodeStyle.BorderColor = Color.HotPink;
            TreeView1.HoverNodeStyle.Font.Bold = true;
            TreeView1.HoverNodeStyle.Font.Italic = true;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change TreeView hover node style programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">TreeView Example: HoverNodeStyle</h2>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView 
             ID="TreeView1"
             runat="server"
             DataSourceID="SiteMapDataSource1"
             Width="275"
             BorderWidth="2"
             BorderColor="HotPink"
             >
        </asp:TreeView>
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.

   


Related asp.net example