Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Web.SiteMap file with several menu items in my web application, such as...

<pre lang="HTML"><pre lang="text"></pre><?xml version="1.0" encoding="utf-8" ?><br />
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" ><br />
<br />
	<siteMapNode url="Default.aspx" title="miTec"><br />
		<siteMapNode url="ATCNQWeb.aspx" title="Tec-NQ Intranet" users="*" /><br />
        <!--siteMapNode url="ActivityScheduling/Default.aspx" title="Activity Scheduling"/--><br />
		<siteMapNode url="JobRegister/Default.aspx" title="miJob Register"/><br />
		<siteMapNode url="Attendance/ClassAttendance.aspx" title="Attendance & Timetables" description="Attendance role marking, class lists and timetables"  /><br />
		<siteMapNode url="Curriculum/Default.aspx" title="Curriculum Basics" /><br />
</pre>


The file is accessed via a default.aspx file using an asp:TreeView tag with DataSource pointing to the above SiteMap file.

How is it possible to set ONE of these menu items to have a different background compared to the other menu items?

Ideally I want the miJob Register to have a Yellow background, whilst the others are all white.

Thank you
Posted

1 solution

I've answered my own question.

In the TreeView tag, use the DataBound event to loop through the nodes, find the node you want using node.Text, and apply a SPAN tag with style="" to control formatting.

ie:

C#
protected void Tree_DataBound(object sender, EventArgs e)
{
    try
    {
        foreach (TreeNode node in TreeView1.Nodes[0].ChildNodes)
        {
            if (node.Text.Equals("miJob Register"))
            {
                node.Text = "<span style='background-color:yellow;'>miJob Register</span>";
                node.ToolTip = "This replaces the old Helpdesk system. Please use miJob Register to raise helpdesk requests as of 2015 onwards.";
                node.
            }
        }
    }
    catch { }
}


Works a treat!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900