bs程序界面中TreeView,欲实现选择父节点时自动选中所有子节点
bs程序界面中TreeView,欲
实现选择父节点时自动选中所有子节点;
当选中父节点下的所有子节点时 自动选中父节点
最好JavaScript怎么实现?
学习加分
[解决办法]
是用VB写的,没测试过,楼主参考参考吧.
<%@ Page Language= "VB " %>
<%@ Import Namespace = "Microsoft.Web.UI.WebControls " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "server ">
Protected Sub TreeView1_TreeNodeCheckChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)
MsgBox( "OK ")
Dim tn As TreeNode = e.Node
MsgBox(tn.Text)
If tn.Checked Then
If tn.ChildNodes.Count > 0 Then
For i As Integer = 0 To tn.ChildNodes.Count - 1
tn.ChildNodes(i).Checked = True
Next
End If
If tn.Parent.ChildNodes.Count > 0 Then
Dim AllChecked As Boolean = True
For i As Integer = 0 To tn.Parent.ChildNodes.Count - 1
If Not tn.Parent.ChildNodes(i).Checked Then
AllChecked = False
End If
Next
If AllChecked Then
tn.Parent.Checked = True
End If
End If
End If
End Sub
</script>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> Untitled Page </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:TreeView ID = "TreeView1 " runat = "server " ShowLines = "true " ShowCheckBoxes= "All " OnTreeNodeCheckChanged= "TreeView1_TreeNodeCheckChanged ">
<Nodes>
<asp:TreeNode Text = "Parent ">
<asp:TreeNode Text = "Child1 " />
<asp:TreeNode Text = "Child2 " />
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
</form>
</body>
</html>