去掉asp.net2.0的树控件刷新功能
在选中树节点时,页面老是刷新。新的树控件中没有可以将刷新功能去掉的属性。如果设置节点的selectAction为None时由无法选中节点。现加入以下脚本去掉刷新功能,并保证能够选中节点时节点变颜色。
脚本文件为:
// JScript 文件
var selectnd=null;
function iniTree(TreeViewName)
{
var tre=document.getElementById(TreeViewName);
for(var i=0;i<tre.children.length;i++)
{
iniChildnode(tre.children[i]);
}
}
function iniChildnode(cnd)
{
if((cnd.tagName=="A")&&(cnd.className!=""))
{
cnd.onclick=clk;
cnd.href="#";
}
else
{
for(var n=0;n<cnd.children.length;n++)
{
iniChildnode(cnd.children[n]);
}
}
}
function clk()
{
if(selectnd!=null)
selectnd.style.backgroundColor="";
var nd=event.srcElement;
nd.style.backgroundColor="#C0FFFF";
selectnd=nd;
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mstree.aspx.cs" Inherits="mstree" %>
<!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>
<script src ="JScript.js" type="text/javascript"></script>
</head>
<body onload="iniTree('Tree');">
<form id="form1" runat="server">
<div>
<asp:TreeView ID="Tree" runat="server" PopulateNodesFromClient="False" ShowLines="True">
<Nodes>
<asp:TreeNode Text="a" Value="a">
<asp:TreeNode Text="a1" Value="a1"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="b" Value="b">
<asp:TreeNode Text="b1" Value="b1"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
<SelectedNodeStyle BackColor="#C0FFFF" BorderColor="Black" />
</asp:TreeView>
</div>
</form>
</body>
</html>


浙公网安备 33010602011771号