你的位置:首页 > ASP.net教程

[ASP.net教程]Button 对 TreeView1 所有节点的全选


protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < this.TreeView1.Nodes.Count; i++)//循环根节点
        {
            if (TreeView1.Nodes[i].Checked == false)//判断是否被选中
            {
                TreeView1.Nodes[i].Checked = true;
                for (int j = 0; j < this.TreeView1.Nodes[i].ChildNodes.Count; j++)//循环当前节点的第一级子节点
                {
                    if (this.TreeView1.Nodes[i].ChildNodes[j].Checked == false)
                    {
                        TreeView1.Nodes[i].ChildNodes[j].Checked = true;
                    }
                }
            }
        }
    }