漂泊雪狼的博客
思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术
posts - 47, comments - 259, trackbacks - 9, articles - 10
ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
Posted on 2006-04-17 13:08
漂泊雪狼
阅读(3212)
评论(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
刷新评论列表
切换模板
发表评论
姓名
[登录]
[注册]
主页
Email
(仅博主可见)
验证码
*
看不清,换一张
内容(请不要发表任何与政治相关的内容)
今天你闪了吗?
《C# 3.0设计模式》65折特惠
Remember Me?
登录
使用高级评论
新用户注册
返回页首
[使用Ctrl+Enter键可以直接提交]
导航:
网站首页
社区
新闻
博问
闪存
网摘
招聘
.NET频道
知识库
找找看
Google站内搜索
China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
China-Pub 计算机绝版图书按需印刷服务
相关文章:
相关链接:
最新IT新闻:
19岁天才黑客发布首个iPhone 3GS破解软件
新浪邮箱大本营粉墨登场!Sina.cn开放注册
IE市场份额首次跌破60%
Google App Engine宕机6小时——云的安全在哪里?
微软新推社交网站Windows Live Planet
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
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
给我留言
查看留言
我参加的小组
jQuery
我参与的团队
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)
随笔分类
(50)
Ajax(11)
ASP.NET(16)
DataBase Others(7)
Microsoft Visual SourceSafe(1)
Oracle(9)
SQL Server(6)
VB Script
随笔档案
(46)
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. Oracle 10g 行列转换(从SQL Server 2000迁移)
2. SQL Server 字段拆分的小技巧
3. CodeSmith Professional 5.0破解下载地址 注册机 keygen
4. Apache log4net与EntLib Logging Application Block使用心得
5. 用Codesmith写的一个的从SQL Server向Oracle导数据的模板
6. 不能将Session保存在其他机器的state server 中问题的解决
7. 在asp.net程序开发中避免编译就要重新登录系统的小技巧
8. 两块钱搞定本本的发烧问题
9. 在ASP.NET AJAX中防止用户多次提交页面
10. ASP.NET2.0MasterPage使用技巧总结
积分与排名
积分 - 84877
排名 - 705
最新评论
1. re: CodeSmith Professional 5.0破解下载地址 注册机 keygen
替换了dll怎么还是要求注册啊?!
--︶ㄣ木べ头
2. re: SQL Server 字段拆分的小技巧
我个人写一个函数就实现了你的功能,但是没试过效率如何。
--GeorgeHuang
3. re: SQL Server 字段拆分的小技巧
这种方法执行效率不会太低,可以看到它的执行计划,而且通用性较强,迁移到Oracle等其他数据比较方便
--漂泊雪狼
4. re: SQL Server 字段拆分的小技巧
这种写法相当复杂,而且执行效率并不高。一般比较推荐的进行字符串拆分的方法是使用CLR创建一个表值函数。
--深蓝
5. re: SQL Server 字段拆分的小技巧
-- 2005 也可以用下面的 SELECT a.arrid ,b.element ,ROW_NUMBER() OVER (PARTITION BY arrid ORDER B...
--流浪的云
阅读排行榜
1. CodeSmith Professional 5.0破解下载地址 注册机 keygen(4924)
2. GridView/DataGrid单元格不换行的问题(4285)
3. Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!(3654)
4. ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript(3212)
5. 关于VSS的多人签出与合并(3148)
评论排行榜
1. Apache log4net与EntLib Logging Application Block使用心得(25)
2. Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!(22)
3. 用CodeSmith编写模板导出Oracle中表的数据(19)
4. 要Gmail、Orkut邀请的请留下你的邮箱(16)
5. 招聘.NET Web程序员【深圳】(14)