[原创]在树控件中点击一个父结点,所有的子节点都被选中!
<script language="javascript">
function CheckNode()
{
var choose;
var indexid;
indexid=TreeView1.clickedNodeIndex;
choose=TreeView1.getTreeNode(indexid).getAttribute('Checked');
var NodeArray=new Array();
NodeArray=TreeView1.getTreeNode(indexid).getChildren();
for(i=0;i<NodeArray.length;i++)
{
var tempindex=indexid+"."+i;
NodeArray[i].setAttribute('Checked',choose);
}
}
</script>
function CheckNode()
{
var choose;
var indexid;
indexid=TreeView1.clickedNodeIndex;
choose=TreeView1.getTreeNode(indexid).getAttribute('Checked');
var NodeArray=new Array();
NodeArray=TreeView1.getTreeNode(indexid).getChildren();
for(i=0;i<NodeArray.length;i++)
{
var tempindex=indexid+"."+i;
NodeArray[i].setAttribute('Checked',choose);
}
}
</script>
<iewc:TreeView id="TreeView1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 96px" runat="server"
ExpandLevel="1">
<iewc:TreeNode CheckBox="True" Text="Node0" Expanded="True">
<iewc:TreeNode CheckBox="True" Text="Node7"></iewc:TreeNode>
<iewc:TreeNode CheckBox="True" Text="Node8"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode CheckBox="True" Text="Node1" Expanded="True">
<iewc:TreeNode CheckBox="True" Text="Node9"></iewc:TreeNode>
<iewc:TreeNode CheckBox="True" Text="Node10"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView>
ExpandLevel="1">
<iewc:TreeNode CheckBox="True" Text="Node0" Expanded="True">
<iewc:TreeNode CheckBox="True" Text="Node7"></iewc:TreeNode>
<iewc:TreeNode CheckBox="True" Text="Node8"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode CheckBox="True" Text="Node1" Expanded="True">
<iewc:TreeNode CheckBox="True" Text="Node9"></iewc:TreeNode>
<iewc:TreeNode CheckBox="True" Text="Node10"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.Attributes.Add("oncheck", "CheckNode()")
End Sub
TreeView1.Attributes.Add("oncheck", "CheckNode()")
End Sub