码迷,mamicode.com
首页 > 其他好文 > 详细

treeview应用

时间:2015-10-11 21:11:15      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

技术分享默认展开树的级别;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);

}
}

treeview应用

标签:

原文地址:http://www.cnblogs.com/wswbk/p/4869938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!