如何使用asp:SiteMapSource为asp:TreeView中的ONE菜单项着色? [英] How to color ONE menu item in asp:TreeView using asp:SiteMapSource?
本文介绍了如何使用asp:SiteMapSource为asp:TreeView中的ONE菜单项着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Web应用程序中有一个包含多个菜单项的Web.SiteMap文件,例如...
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>
使用asp:TreeView标记通过default.aspx文件访问该文件,其中DataSource指向上面的SiteMap文件。
与其他菜单项相比,如何将其中一个菜单项设置为具有不同的背景?
理想情况下我想要miJob注册黄色背景,其他都是白色。
谢谢
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
推荐答案
I回答了我自己的问题。
在TreeView标签中,使用DataBound事件循环遍历节点,使用node.Text查找所需节点,然后应用一个带有style =的SPAN标签来控制格式。
ie:
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:
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!
这篇关于如何使用asp:SiteMapSource为asp:TreeView中的ONE菜单项着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文