漂泊雪狼的博客
思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术
posts - 49, comments - 263, trackbacks - 9, articles - 10
ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
Posted on 2006-04-17 13:08
漂泊雪狼
阅读(3327)
评论(0)
编辑
收藏
网摘
所属分类:
ASP.NET
ASP.NET 2.0 TreeView has many built-in features such as showing a checkbox for all the Tree Nodes. Node level formating, style, etc., Enabling the
ShowCheckBoxes="All"
property sets it to show a checkbox for all the nodes. The other options are
Leaf
,
None
,
Parent
and
Root
which show checkboxes at the respective node levels.
None
doesnt display CheckBoxes.
When we set
ShowCheckBoxes="All",
we would like to provide a feature where people can select the checkbox on the Root Node so that all the other checkboxes are checked automatically. Basically, when the parent node is checked, all the child nodes should be checked automatically.
It would be intuitive to accomplish this task at the client side without involving a postback.
The following code snippet helps in accomplishing the same.
TreeView Declaration
<asp:TreeView ID="TreeView1" Runat="server" DataSourceID="XmlDataSource1" onclick="client_OnTreeNodeChecked();" ShowCheckBoxes="all">
<DataBindings>
<asp:TreeNodeBinding DataMember="Category" ValueField="ID" TextField="Name"></asp:TreeNodeBinding>
<asp:TreeNodeBinding DataMember="Description" ValueField="Value" TextField="Value"></asp:TreeNodeBinding>
</DataBindings>
</asp:TreeView>
In the above TreeView declaration Code, you can find the property onclick="client_OnTreeNodeChecked();" event which actually is the JavaScript function which would accomplish this task.
The Javascript Code snippet is as follows:-
全选Javascript
1
function
client_OnTreeNodeChecked()
2
{
3
var
obj
=
window.event.srcElement;
4
var
treeNodeFound
=
false
;
5
var
checkedState;
6
if
(obj.tagName
==
"
INPUT
"
&&
obj.type
==
"
checkbox
"
)
7
{
8
var
treeNode
=
obj;
9
checkedState
=
treeNode.checked;
10
do
11
{
12
obj
=
obj.parentElement;
13
}
14
while
(obj.tagName
!=
"
TABLE
"
)
15
var
parentTreeLevel
=
obj.rows[
0
].cells.length;
16
var
parentTreeNode
=
obj.rows[
0
].cells[
0
];
17
var
tables
=
obj.parentElement.getElementsByTagName(
"
TABLE
"
);
18
var
numTables
=
tables.length
19
if
(numTables
>=
1
)
20
{
21
for
(i
=
0
; i
<
numTables; i
++
)
22
{
23
if
(tables[i]
==
obj)
24
{
25
treeNodeFound
=
true
;
26
i
++
;
27
if
(i
==
numTables)
28
{
29
return
;
30
}
31
}
32
if
(treeNodeFound
==
true
)
33
{
34
var
childTreeLevel
=
tables[i].rows[
0
].cells.length;
35
if
(childTreeLevel
>
parentTreeLevel)
36
{
37
var
cell
=
tables[i].rows[
0
].cells[childTreeLevel
-
1
];
38
var
inputs
=
cell.getElementsByTagName(
"
INPUT
"
);
39
inputs[
0
].checked
=
checkedState;
40
}
41
else
42
{
43
return
;
44
}
45
}
46
}
47
}
48
}
49
}
50
0
0
0
(请您对文章做出评价)
«
上一篇:
Asp.net 2.0 中的TreeView的右键菜单(Context Menus on the TReeView - IE Specific)
»
下一篇:
网址收藏
注册用户登录后才能发表评论,请
登录
或
注册
。
IT新闻
:
·
知名扩展 Firebug 的简化版登陆 Chrome
·
Google 悄悄地启用 1e100.net,打枪地不要
·
从 Google 代码库找到的好东西
·
苹果在线商店临时关闭 或将推新Macbook
·
豆瓣网推出豆瓣电台iPhone客户端
每天10分钟,轻松学英语
专题:
iPad
jQuery
Windows 7
网站导航:
博客园首页
IT新闻
个人主页
闪存
程序员招聘
社区
博问
网摘
China-pub 计算机图书网上专卖店!6.5万品种2-8折!
China-Pub 计算机绝版图书按需印刷服务
相关搜索:
ASP.NET
在知识库中查看:
ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
Powered by:
博客园
Copyright © 漂泊雪狼
导航
博客园
首页
新随笔
联系
订阅
管理
公告
给我留言:
MSN:
E-Mail:
您是第 位访客
访问统计:
我的主页
个人资料
我的闪存
发短消息
<
2006年4月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
我参与的团队
ASP.NET AJAX (Atlas)学习(0/0)
.NetFramework3.0 & 3.5(WCF,WPF,WF)团队(0/0)
Silverlight学习与研究(0/0)
数据库团队(0/0)
我的标签
SQL Server
(2)
Oracle
(1)
随笔分类
(54)
Ajax(12)
ASP.NET(16)
DataBase Others(7)
EXTJS(3)
Microsoft Visual SourceSafe(1)
Oracle(9)
SQL Server(6)
VB Script
随笔档案
(49)
2009年11月 (3)
2009年5月 (1)
2009年4月 (1)
2008年9月 (2)
2008年8月 (1)
2008年1月 (1)
2007年12月 (2)
2007年11月 (1)
2007年10月 (1)
2007年9月 (1)
2007年6月 (1)
2007年4月 (3)
2007年3月 (3)
2007年1月 (2)
2006年12月 (1)
2006年11月 (4)
2006年10月 (1)
2006年8月 (1)
2006年7月 (5)
2006年6月 (2)
2006年4月 (4)
2006年3月 (8)
文章分类
(11)
Excel操作(3)
脚本知识(2)
其他(4)
数据库(2)
文章档案
(10)
2006年12月 (1)
2006年11月 (1)
2006年9月 (1)
2006年8月 (1)
2006年7月 (1)
2006年6月 (3)
2006年3月 (2)
相册
个人相册
常用链接
24小时学习网
dotnettiers
Enterprise Library 3.1中文文档
Google
谷歌搜索
Microsoft patterns & practices
MS Enterprise Library
百度搜索
百度搜索
层叠样式表手册
动态网站制作指南
就爱E书网
无忧视窗
资源中国
个人链接
MSN共享空间
网易相册
友情博客
newwind
VirtualMJ
中文爱百科
可信赖的中文百科全书
最新随笔
1. ExtJS中grid的JsonStore、Ext.PagingToolbar带条件查询问题
2. ExtJS 中Grid使用SimpleStore、多选框的方法
3. ExtJS Window 最小化的一种方法
4. Oracle 10g 行列转换(从SQL Server 2000迁移)
5. SQL Server 字段拆分的小技巧
6. CodeSmith Professional 5.0破解下载地址 注册机 keygen
7. Apache log4net与EntLib Logging Application Block使用心得
8. 用Codesmith写的一个的从SQL Server向Oracle导数据的模板
9. 不能将Session保存在其他机器的state server 中问题的解决
10. 在asp.net程序开发中避免编译就要重新登录系统的小技巧
积分与排名
积分 - 94738
排名 - 781
最新评论
1. Re:CodeSmith Professional 5.0破解下载地址 注册机 keygen
注册号在那里啊?
--人云我亦云
2. Re:在TOAD(癞蛤蟆)中执行Oracle存储过程返回游标结果集
一直报错~为什么~
--hemin
3. Re:在TOAD(癞蛤蟆)中执行Oracle存储过程返回游标结果集
create or replace package returncursor is type cur_cj is ref cursor ; procedure find(emp out cur_cj)...
--hemin
4. Re:在TOAD(癞蛤蟆)中执行Oracle存储过程返回游标结果集
啊啊啊~~我在PL/SQL中也不能解决,不知道为什么~~~帮下我啊~
--hemin
5. re: CodeSmith Professional 5.0破解下载地址 注册机 keygen
替换了dll怎么还是要求注册啊?!
--︶ㄣ木べ头
阅读排行榜
1. CodeSmith Professional 5.0破解下载地址 注册机 keygen(7065)
2. GridView/DataGrid单元格不换行的问题(4589)
3. Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!(4064)
4. 关于VSS的多人签出与合并(3327)
5. ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript(3327)
评论排行榜
1. Apache log4net与EntLib Logging Application Block使用心得(25)
2. Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!(22)
3. 用CodeSmith编写模板导出Oracle中表的数据(19)
4. 要Gmail、Orkut邀请的请留下你的邮箱(16)
5. CodeSmith Professional 5.0破解下载地址 注册机 keygen(14)