相对于之前发过一个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. PeopleSoft Home Subdirectories

    PeopleSoft Home Subdirectories appserv — home to the Application Server and Process Scheduler Server ...

  2. 基于eBox旋转编码器

    在电子产品设计中,经常会用到旋转编码开关,比如数码电位器等,它的英文名翻译过来就是Rotary Encoder Switch.常见的有5pin和3pin产品.5pin实在左右旋转的基础上增加了向下按得 ...

  3. mysql 性能优化方案1

    网 上有不少mysql 性能优化方案,不过,mysql的优化同sql server相比,更为麻烦与复杂,同样的设置,在不同的环境下 ,由于内存,访问量,读写频率,数据差异等等情况,可能会出现不同的结果 ...

  4. javascript中正则表达式的基础语法

    × 目录 [1]定义 [2]特点 [3]元字符[4]转义字符[5]字符组[6]量词[7]括号[8]选择[9]断言[10]模式[11]优先级[12]局限性 前面的话 正则表达式在人们的印象中可能是一堆无 ...

  5. wex5 实战 图片触摸放大移动插件easyzoom的使用与集成

    一 前言 客户的需求就是上帝的召唤. 作为一个开发人员,或者软件从业者,客户的要求就是准则. 遇到一个客户,让我做一个图片放大,但是移动拖拽要定位精准.之前研究过一个hammer插件,多次尝试放大后的 ...

  6. 后台调取前台js中的函数

    Page.ClientScript.RegisterStartupScript(this.GetType(), "setPicType", "setPicType(2); ...

  7. 描述性统计分析-用脚本将统计量函数批量化&分步骤逐一写出

    计算各种描述性统计量函数脚本(myDescriptStat.R)如下: myDescriptStat <- function(x){ n <- length(x) #样本数据个数 m &l ...

  8. 简单利用Scanner对文件进行解析

    public class AvPrice{    static int count = 0;    static int sum = 0;    public static void main(Str ...

  9. 用Python生成组织机构代码,附源码

    #!/usr/bin/python import random def haoma(): ww = [3,7,9,10,5,8,4,2]#suan fa yin zi cc = [] dd=0 for ...

  10. ubuntu gtk2.0 一个简单完整的窗口

    //gtk_main();开了线程,关闭窗口并不能退出程序,需要手动添加 //gtk2.0,window quit compelete example #include <gtk/gtk.h&g ...