Problem description: There are only four nodes in the TreeView in the frameset. After opening one, close the other three nodes.
At first, I wrote it in TreeView1_Expand, which works, but you need to set autopostback to true. It will look ugly when refreshing. I looked for information on the Internet and related topics are as follows:
==================
1. "Do not submit when expanding, submit only when changing the selected node"
2. "Enable TreeView to automatically retract all other expanded nodes after expanding a node, that is, there is only one expanded node at the same time."
3. "Solution to TreeView expansion without flickering"
4. "TreeView Special Discussion"
5. "Research on TreeView JavaScript Control Method"
==================
There is a javascript script above that is well written, but after trying it for a long time, I always get errors.
So I wrote one myself.
<script language="JavaScript">
function initTree()
{
var tree = document.all["TreeView1"];
tree.attachEvent("onexpand", SelectedIndexChange); //Append an event
}
function SelectedIndexChange()
{
var temp = this.TreeView1.clickedNodeIndex;
var nodes = new Array();
nodes = this.TreeView1.getChildren();
for(i=0;i<nodes.length;i++)
{
if(i!=temp)
{
if(i<10)
nodeIndex = "0"+i;//I only used four nodes, try it with more than ten nodes.
this.TreeView1.getTreeNode(nodeIndex).setAttribute('expanded','false');
}
}
}
</script>
Finally, write one in the body
<body onload="initTree();">
It's ready to use.
Of course, you can also write javascript in page_load like in the "TreeView Forum", but that would be very troublesome and error-prone.