补充问一问题,在最底一层的子节点上面,我都加上了CheckBox,现在要求:
(1)有相同父节点的一组子节点中只能选择一个,选另一个时,原来选中的变为不选中。
(2)每一组(一组只有相同的父节点的)最底层的子节点,必须要选择一个。
<
script language
=
"
javascript
"
>
function CheckOne()
{
var cIndex = TreeView2.clickedNodeIndex;
var tmp = cIndex.split( " . " );
if (tmp.length == 3 ) // 代表都是第3层节点
{
var pNode = TreeView2.getTreeNode(cIndex);
var parentNode = pNode.getParent();
var NodeArray = new Array();
NodeArray = parentNode.getChildren();
for ( var i = 0 ;i < NodeArray.length;i ++ )
{
var cNode = NodeArray[i];
cNode.setAttribute('Checked',' false ');
if (cNode.getAttribute( " Text " ) == pNode.getAttribute( " Text " ))
{
cNode.setAttribute('Checked',' true ');
}
}
}
}
</ script >
function CheckOne()
{
var cIndex = TreeView2.clickedNodeIndex;
var tmp = cIndex.split( " . " );
if (tmp.length == 3 ) // 代表都是第3层节点
{
var pNode = TreeView2.getTreeNode(cIndex);
var parentNode = pNode.getParent();
var NodeArray = new Array();
NodeArray = parentNode.getChildren();
for ( var i = 0 ;i < NodeArray.length;i ++ )
{
var cNode = NodeArray[i];
cNode.setAttribute('Checked',' false ');
if (cNode.getAttribute( " Text " ) == pNode.getAttribute( " Text " ))
{
cNode.setAttribute('Checked',' true ');
}
}
}
}
</ script >
<
body
MS_POSITIONING
="GridLayout"
>
< form id ="Form1" method ="post" runat ="server" >
< iewc:TreeView id ="TreeView2" style ="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 176px" runat ="server" >
< iewc:TreeNode Text ="Node0" Expanded ="True" >
< iewc:TreeNode Text ="Node2" Expanded ="True" >
< iewc:TreeNode Checked ="True" CheckBox ="True" Text ="Node4" ></ iewc:TreeNode >
< iewc:TreeNode CheckBox ="True" Text ="Node5" ></ iewc:TreeNode >
< iewc:TreeNode CheckBox ="True" Text ="Node6" ></ iewc:TreeNode >
< iewc:TreeNode CheckBox ="True" Text ="Node7" ></ iewc:TreeNode >
</ iewc:TreeNode >
< iewc:TreeNode Text ="Node3" ></ iewc:TreeNode >
</ iewc:TreeNode >
< iewc:TreeNode Text ="Node1" ></ iewc:TreeNode >
</ iewc:TreeView >
</ form >
</ body >
< form id ="Form1" method ="post" runat ="server" >
< iewc:TreeView id ="TreeView2" style ="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 176px" runat ="server" >
< iewc:TreeNode Text ="Node0" Expanded ="True" >
< iewc:TreeNode Text ="Node2" Expanded ="True" >
< iewc:TreeNode Checked ="True" CheckBox ="True" Text ="Node4" ></ iewc:TreeNode >
< iewc:TreeNode CheckBox ="True" Text ="Node5" ></ iewc:TreeNode >
< iewc:TreeNode CheckBox ="True" Text ="Node6" ></ iewc:TreeNode >
< iewc:TreeNode CheckBox ="True" Text ="Node7" ></ iewc:TreeNode >
</ iewc:TreeNode >
< iewc:TreeNode Text ="Node3" ></ iewc:TreeNode >
</ iewc:TreeNode >
< iewc:TreeNode Text ="Node1" ></ iewc:TreeNode >
</ iewc:TreeView >
</ form >
</ body >
最后在加上一个后台代码:
Private
Sub Page_Load()
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TreeView2.Attributes.Add("oncheck", "javascript:CheckOne();")
End Sub
TreeView2.Attributes.Add("oncheck", "javascript:CheckOne();")
End Sub