When selecting a tree node, the page is always refreshed. The new tree control does not have any properties that can be removed from the refresh function. If the node selectaction is set to none, the node cannot be selected. The following script is added to remove the refresh function and ensure that the node color can be changed when it is selected.
The script file is:
// JScript File
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;
}
The aspx file is <% @ 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 > No title page </ 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 = "" Value = "" >
< 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 >