Reputation: 23
I have a TreeView
with a checkbox in for each node. I also have one checkbox outside of the tree which, when clicked needs to uncheck all of the checkboxes inside of the tree.
How can I do that?
Upvotes: 0
Views: 3565
Reputation: 3659
Try
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
//if checkbox is unchecked
if (!CheckBox1.Checked)
{
//uncheck all checkboxes of tree view
foreach (TreeNode node in TreeView.Nodes)
{
node.Checked = false;
}
}
}
Add an event handler on the checkbox outside the panel
<asp:CheckBox id="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" />
Upvotes: 1
Reputation: 3431
Use recursion to iterate the hole treeview and set the checked-property to true
private void Node(TreeNode root)
{
root.Checked = true;
foreach (TreeNode childNode in root.Nodes)
{
childNode.Checked = true;
Node(childNode);
}
}
Upvotes: 1