asp.net - How to change SiteMapPath node style programmatically

Node style in SiteMapPath
SiteMapPath is an asp.net web server control. sitemappath control's NodeStyle property gets the style used for the displayed text for all nodes in the site navigation path. the NodeStyle property value type is System.Web.UI.WebControls.Style. this 'Style' value contains the style settings for the display text in the sitemappath control.

so by using this property we can customize the sitemappath node style such as change the background color, text color, font name, text size, border color, border style etc.

the following asp.net c# example code demonstrate us how can we set or change sitemappath node style programmatically at run time in an asp.net application.
ButtonExample.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        SiteMapPath1.NodeStyle.BackColor = Color.Crimson;
        SiteMapPath1.NodeStyle.BorderWidth = 1;
        SiteMapPath1.NodeStyle.BorderColor = Color.DarkRed;
        SiteMapPath1.NodeStyle.ForeColor = Color.PaleGoldenrod;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change node style in SiteMapPath, NodeStyle</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">SiteMapPath Example: NodeStyle</h2>
        <asp:SiteMapPath 
             ID="SiteMapPath1" 
             runat="server"
             >
        </asp:SiteMapPath>
        <br /><br />
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DarkGreen"
             Text="Change SiteMapPath NodeStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.

   






Related asp.net examples