Hello all, im trying to sort some code out that will enable me to automatically check any child checkboxs when a partent checkbox is checked (and vice versa, if a parent checkbox is unchecked then all child checkboxes should be unchecked).
I have not been able to find a way of achiving this be only using asp.net code, there im trying to use javascript code to achive this.
i think this code is getting there, but i still need some help
I have not been able to find a way of achiving this be only using asp.net code, there im trying to use javascript code to achive this.
i think this code is getting there, but i still need some help
Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.ShowCheckBoxes = TreeNodeTypes.All;
}
</script>
<script type="text/javascript" language="javascript">
window.onload = function() {
var cbx = document.getElementById("tree1");
cbx.onclick = function() {
if (cbx.checked) {
applyCheck(true);
} else {
applyCheck(false);
}
}
}
function applyCheck(bool) {
for (var x=1; 100; x++) {
tree1_[x].checked = true;
}
}
</script>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode Text="Home" Value="tree1">
<asp:TreeNode Text="Child" Value="Tree1_1">
<asp:TreeNode Text="Grandchild" Value="tree1_1_1"></asp:TreeNode>
<asp:TreeNode Text="Grandchild1" Value="tree1_1_2"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Child" Value="Tree1_2">
<asp:TreeNode Text="Grandchild" Value="tree1_2_1"></asp:TreeNode>
<asp:TreeNode Text="Grandchild1" Value="tree1_2_2"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
</form>
</body>
</html>