ASP.NET树视图图像背景
我有一个树视图控件,我想为它提供背景图像。我的代码当前如下所示:ASP.NET树视图图像背景,asp.net,asp.net-2.0,Asp.net,Asp.net 2.0,我有一个树视图控件,我想为它提供背景图像。我的代码当前如下所示: <asp:Image ImageUrl="~/images/mypic.gif" runat="server" Width="150px" /> <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ImageSet="Arrows">
<asp:Image ImageUrl="~/images/mypic.gif" runat="server" Width="150px" />
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1"
ImageSet="Arrows">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True"
HorizontalPadding="0px" VerticalPadding="0px" ForeColor="#5555DD" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
treeview CssClass有一个属性,您可以通过css为其提供一个图像
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1"
CssClass="classname" ImageSet="Arrows">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True"
HorizontalPadding="0px" VerticalPadding="0px" ForeColor="#5555DD" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
然后在css中
.类名
{
背景图像:url(“图像路径”);
}我认为实现这一点的最佳方法是使用CSS。我不知道TreeView控件会显示什么样的html,但是如果它是块元素,您应该能够设置background属性来显示您的图像。
一个简单的方法是将你的树视图围成一个块,并在上面设置css样式
<div id="treeNav">
<asp:TreeView .........
</asp:TreeView>
</div>
#treeNav
{
background-image: url(my-image.png);
}