当前位置: 代码迷 >> ASP.NET >> 请问关于treeview节点点击变色的有关问题
  详细解决方案

请问关于treeview节点点击变色的有关问题

热度:4407   发布时间:2013-02-25 00:00:00.0
请教关于treeview节点点击变色的问题
<Nodes>
  <asp:TreeNode Text="首页" Value="首页" NavigateUrl="~/系统首页.aspx"></asp:TreeNode>
  <asp:TreeNode Text="用户资源管理" Value="用户资源管理">
  <asp:TreeNode Text="用户" Value="用户" NavigateUrl="~/信息中心内容页.aspx"></asp:TreeNode>
  <asp:TreeNode Text="组织机构管理" Value="组织机构管理" NavigateUrl="~/组织机构管理中间导航页.aspx"></asp:TreeNode>

C# code
  protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)         {        TreeView1.SelectedNodeStyle.ForeColor = Color.Blue; }


本人发现奇怪的现象无法解决,注意我是在母版页中实现功能的。问题是:
其一,做了NavigateUrl="~/****.aspx"后的节点,TreeView1_SelectedNodeChanged这个事件进不去,不可改变颜色;
其二,我接下来不用这个事件,PageLoad里面直接写 TreeView1.SelectedNodeStyle.ForeColor = Color.Blue;这句语句,发现无论点击什么节点,这句话都执行的,但是有NavigateUrl的节点,因为跳转,节点不变蓝。
其三,我觉得应该是treeview每次点击都要刷新页面的结果,会跳一下,不知能否解决。

还有用css的话
CSS code
 A:link {        COLOR: #000000; TEXT-DECORATION: none        }        A:visited {            COLOR: #000000; TEXT-DECORATION: none        }        A:hover {            COLOR: #DD5555; TEXT-DECORATION: none        }        A:active {            COLOR: #DD5555; TEXT-DECORATION: none;        }

点击后颜色不变。感觉不可保留。

请求各位大虾解答,感激不尽哈~

------解决方案--------------------------------------------------------
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeView.aspx.cs" Inherits="Galsun.Test.Web.TreeView" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><script>    var preNode;    function selval(obj, url, target) {        //alert(obj.innerHTML);        /*        var cb = obj.parentNode.parentNode.getElementsByTagName("input");                if (cb.length > 0)            cb[0].checked = true;        document.getElementById("<%= txt_path.ClientID %>").value = obj.innerHTML;        */        if (preNode) preNode.style.color = "";        obj.style.color = "#FF0000";        preNode = obj;        //document.getElementById("<%= txt_path.ClientID %>").value = obj;        window.open(url, target);    }</script><body>    <form id="form1" runat="server" >    <div>            <asp:TextBox ID="txt_path" runat="server" Width="422px"></asp:TextBox>            <asp:TreeView ID="TreeView1" runat="server" ImageSet="XPFileExplorer"             NodeIndent="15">            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />            <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black"                 HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />            <ParentNodeStyle Font-Bold="False" />            <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False"                 HorizontalPadding="0px" VerticalPadding="0px" />        </asp:TreeView>        <iframe name="Right" src="http://www.hao123.com" width="600" height="300"></iframe>    </div>    </form></body></html>
  相关解决方案