如何在TreeView控件更改选定的节点的颜色
问题描述:
在asp.net网站我使用TreeView
从xml
文件如何在TreeView控件更改选定的节点的颜色
显示的数据是这样的TreeView的HTML代码
<asp:TreeView ID="trvPILDeepSearch" runat="server" ImageSet="Simple" BackColor="#F8F8F8" BorderWidth="5px" BorderColor="#F8F8F8" LeafNodeStyle-CssClass="leafnode" Width="600px" >
<DataBindings>
<asp:TreeNodeBinding DataMember="Parent" TextField="TEXT" SelectAction="None" />
<asp:TreeNodeBinding DataMember="Child" TextField="TEXT" SelectAction="None" />
</DataBindings>
</asp:TreeView>
现在我想更改父节点的文本颜色,是否有可能改变颜色只有在选择的节点
Name1 <-- Change the color of this
Detail1
Detail2
Name2 <-- Change the color of this
Detail2
Detail2
答
您可以为添加RootNodeStyle
树视图:
/* Styles: put this at style section or at your .css file */
.rootNodeLinkStyle a:link
{
color: Red;
}
.rootNodeLinkStyle a:hover
{
color: pink;
text-decoration:underline;
}
在的.aspx:CSS类添加到RootNodeStyle
如下:
<asp:TreeView ID="trvPILDeepSearch" runat="server" ImageSet="Simple" BackColor="#F8F8F8" BorderWidth="5px" BorderColor="#F8F8F8" LeafNodeStyle-CssClass="leafnode" Width="600px" >
<DataBindings>
<asp:TreeNodeBinding DataMember="Parent" TextField="TEXT" SelectAction="None" />
<asp:TreeNodeBinding DataMember="Child" TextField="TEXT" SelectAction="None" />
</DataBindings>
<RootNodeStyle CssClass="rootNodeLinkStyle" />
</asp:TreeView>
你有没有尝试编辑树视图的NodeStyle-的CssClass属性? –
@ A.B.Cade我是盲人:(有一个属性叫做ParentNodeStyle-ForeColor,它工作正常 – Nalaka526