默认展开树的级别;0是不展开;1是展开一级;
public void treeBind()
{
TreeNode root = new TreeNode();//创建对象
root.Text = "汉企数据通软件有限公司";
root.Value = "H001";
root.SelectAction = TreeNodeSelectAction.None;//去掉超链接属性;
TreeView1.Nodes.Add(root);
List<Department> list = new Function().SelectPart();
List<Worker> data=new List<Worker>();
foreach (Department item in list)
{
TreeNode firstNode = new TreeNode();
firstNode.Text = item.Department1;
firstNode.Value = item.DepartCode;
firstNode.SelectAction = TreeNodeSelectAction.None;
root.ChildNodes.Add(firstNode);//根节点添加
List<Worker>arr= new Function().SelectWorker(item.Department1);
foreach (Worker workers in arr)
{
TreeNode child = new TreeNode();
child.Text = workers.Wname;
child.Value = workers.Wid.ToString();
child.SelectAction = TreeNodeSelectAction.None;
firstNode.ChildNodes.Add(child);
}
}
//js checkedbox选根节点全选
function OnTreeNodeChecked() {
var ele = event.srcElement;
if (ele.type == ‘checkbox‘) {
var childrenDivID = ele.id.replace(‘CheckBox‘, ‘Nodes‘);
var div = document.getElementById(childrenDivID);
if (div != null) {
var checkBoxs = div.getElementsByTagName(‘INPUT‘);
for (var i = 0; i < checkBoxs.length; i++) {
if (checkBoxs[i].type == ‘checkbox‘)
checkBoxs[i].checked = ele.checked;
}
}
CheckOn(ele);
}
}
function CheckOn(obj) {
var div1 = WebForm_GetParentByTagName(obj, ‘DIV‘);
if (div1 != null) {
var checkBoxs = div1.getElementsByTagName(‘INPUT‘);
var parentCheckBoxID = div1.id.replace(‘Nodes‘, ‘CheckBox‘);
var parentCheckBox = document.getElementById(parentCheckBoxID);
if (parentCheckBox != null) {
parentCheckBox.checked = true;
CheckOn(parentCheckBox);
CheckOn(parentCheckBox);
}
}