相对于之前发过一个TreeView控件的使用方法

本次利用js操作,页面无刷新,性能提高

Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉

前台

    <style>
.tn td {
height: 18px;
line-height: 18px;
display: flex;
} .tn tr {
display: flex;
} .tn a {
line-height: 18px;
color: black;
}
</style>

Css Code

                        <asp:TreeView ID="tv_roleaction" runat="server" ShowCheckBoxes="All" CssClass="tn" ShowLines="True" CollapseImageToolTip="折叠">
</asp:TreeView>

Html Code

        var nodecheck = {
init: function () {
//配合asp treeview使用
//需在页面加载时设置 this.TreeView.Attributes.Add("onclick", "nodecheck.init()");
var element = event.srcElement;
if (element.tagName == "INPUT" && element.type == "checkbox") {
var checkedState = element.checked;
while (element.tagName != "TABLE") { //获取当前节点所在的table
element = element.parentElement;
}
this.SetChildChecked(element, checkedState);
this.SetParentChecked(element, checkedState);
}
},
SetChildChecked: function (table, checked) {
table = table.nextSibling;
if (table == null || !table.translate) //判断有没有子节点
return;
var childTables = table.getElementsByTagName("TABLE");//获取所有子节点所在的table
for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++) {
this.SetNodeChecked(childTables[tableIndex], checked);
}
},
SetParentChecked: function (table, checked) {
if (table == null || table.rows[0].cells.length == 2) {
return;
}
var parentTable = table.parentElement.previousElementSibling;//获得父级table if (parentTable == null || !parentTable.translate) //没有父节点就停止
return; //判断父节点下有没有被选中的节点
node = parentTable.nextSibling;
var ifnochecked = true;
if (node == null || !node.translate) //判断有没有子节点 --没有子节点就停止
return;
var childTables = node.getElementsByTagName("TABLE");//获取所有子节点所在的table
for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++) {
if (this.GetNodeChecked(childTables[tableIndex])) {
ifnochecked = false;
this.SetNodeChecked(parentTable, true);
break;
}
}
if (ifnochecked) {
this.SetNodeChecked(parentTable, false);
} this.SetParentChecked(parentTable, checked);
},
SetNodeChecked: function (table, checked) { //设置节点选中状态
if (this.GetNode(table).length == 1) {
checkboxes[0].checked = checked;
}
},
GetNodeChecked: function (table) { //获取节点选中状态
if (this.GetNode(table).length == 1) {
return checkboxes[0].checked;
}
},
GetNode: function (table) { //获取节点
var checkboxIndex = table.rows[0].cells.length - 1;
var cell = table.rows[0].cells[checkboxIndex];
return checkboxes = cell.getElementsByTagName("INPUT");
}
};

Js Code

后台

        protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//调用递归函数,完成树形结构的生成
AddTree(, (TreeNode)null);
this.tv_roleaction.Attributes.Add("onclick", "nodecheck.init()");
}
} //递归添加树的节点
public void AddTree(int ParentID, TreeNode pNode)
{
DataView dvTree = new DataView(SysActionBLL.GetInstance().GetList(""));
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[FPARENTACTIONID] = " + ParentID; foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
Node.Value = Row["FACTIONID"].ToString();
Node.Text = Row["FACTIONNAME"].ToString();
Node.Expanded = true;
if (pNode == null)
{ //添加根节点
tv_roleaction.Nodes.Add(Node);
}
else
{ //?添加当前节点的子节点
pNode.ChildNodes.Add(Node);
} //判断当前角色是否拥有该权限
if (roleaction.Count > && roleaction.Find(p => p.ToString() == Row["FACTIONID"].ToString()) != null)
{
Node.Checked = true;
}
AddTree(Int32.Parse(Row["FACTIONID"].ToString()), Node); //再次递归
}
} /// <summary>
/// 保存
/// </summary>
protected void btnSave_click(object sender, EventArgs e)
{
//获取选中节点的value集合
List<object> roleaction = new List<object>();
foreach (TreeNode node in tv_roleaction.CheckedNodes)
{
roleaction.Add(node.Value);
}
}

C# Code

asp TreeView控件的使用的更多相关文章

  1. 【ASP.NET 进阶】TreeView控件学习

    这几天上班没事做,也不好打酱油,学点没接触过的新东西吧,基本了解了下TreeView控件. TreeView 控件用于在树结构中显示分层数据,例如目录或文件目录等. 下面看代码吧: 1.效果图 2.静 ...

  2. ASP.NET - TreeView控件,只操作最后一级节点

    效果: 使用母板页进行,左右页面进行跳转. 绑定TreeView控件:http://www.cnblogs.com/KTblog/p/4792302.html 主要功能: 点击节点的时候,只操作最后一 ...

  3. TreeView控件例子

    XmL文件代码: <?xml version="1.0" encoding="utf-8" ?> <Area> <Province ...

  4. TreeView控件绑定数据库

    1.在设计视图里面的代码 <form id="form1" runat="server"> <div> <h1>两个表< ...

  5. ASP.NET控件属性大全

    ASP.NET控件属性大全 DataGridView 控件DataGridView 控件提供用来显示数据的可自定义表.使用 DataGridView 类,可以自定义单元格.行.列和边框. 注意Data ...

  6. TreeView控件使用

    treeView1.SelectedNode = treeView1.Nodes[0];  //选中当前treeview控件的根节点为当前节点添加子节点:  TreeNode tmp; tmp = n ...

  7. 基于Treeview控件遍历本地磁盘

    一.前言 Treeview控件常用于遍历本地文件信息,通常与Datagridview与ImageList搭配.ImageList控件用于提供小图片给TreeView控件,DatagridView通常显 ...

  8. asp.net <asp:Content>控件

    <asp:Content ID="Content2" ContentPlaceHolderID="CPH_MainContent" runat=" ...

  9. Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式

    首先是头文件,内容如下: #include <tchar.h> #include "..\CommonFiles\CmnHdr.h" #include <Wind ...

随机推荐

  1. hadoop 多表join:Map side join及Reduce side join范例

    最近在准备抽取数据的工作.有一个id集合200多M,要从另一个500GB的数据集合中抽取出所有id集合中包含的数据集.id数据集合中每一个行就是一个id的字符串(Reduce side join要在每 ...

  2. windows编程环境

    自行下载VS2010官方原版并破解你也可以从微软官方直接下载VS2010 正式版,然后自行破解.Microsoft Visual Studio 2010官方下载地址如下:页面:http://www.m ...

  3. 01.线性表 ArrayList

    public class MyArrayList { //容量 ; //存放数组元素 private object[] _items; //数组大小 private int _size; //元素个数 ...

  4. js 控制Div循环显示 非插件版

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. data([key],[value])

    概述 在元素上存放或读取数据,返回jQuery对象. 当参数只有一个key的时候,为读取该jQuery对象对应DOM中存储的key对应的值,值得注意的是,如果浏览器支持HTML5,同样可以读取该DOM ...

  6. 为何iPhone6 Plus的逻辑分辨率是2208×1242,屏幕实际分辨率却是1920×1080

    因为除了iPhone 6+以外,其他所有iPhone的DPI是一致的,都是326,用@2x的素材.但是6+的实际DPI是401,理论上苹果应该用401/326 * @2x=@2.46x的素材,但是这个 ...

  7. [MKRCVCD]Burning SDK report AddFile error

    在使用Pipe通信的使用,我使用GetProcessExitCode这个函数来获取返回值.而ExitCode的定义为DWORD DWORD的原型为unsigned long,在32位程序中,DWORD ...

  8. java equals和==的区别

    大概说equals和==都比较的是什么: 1. boolean tem = a == b; 首先==比较的肯定是地址,从堆栈的角度说也就是说==比较的是栈上面的内容.因为栈是用来存放地址或是java中 ...

  9. 10 个实用技巧,让 Finder 带你飞

    Finder 是 Mac 电脑的系统程序,有的功能类似 Windows 的资源管理器.它是我们打开 Mac 首先见到的「笑脸」,有了它,我们可以组织和使用 Mac 里的几乎所有东西,包括应用程序.文件 ...

  10. ajax 跨域请求

    1. $.ajax({ type: "get", async: false, url: "http://61.160.194.208:8383/Api/login?acc ...