漂泊雪狼的博客
思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术
posts - 45, comments - 245, trackbacks - 9, articles - 10
ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
Posted on 2006-04-17 13:08
漂泊雪狼
阅读(3065)
评论(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
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
人才
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2007-04-05 12:28 编辑过
Google站内搜索
China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
相关文章:
相关链接:
所属分类的其他文章:
不能将Session保存在其他机器的state server 中问题的解决
在asp.net程序开发中避免编译就要重新登录系统的小技巧
在ASP.NET AJAX中防止用户多次提交页面
ASP.NET2.0MasterPage使用技巧总结
【续】用ObjectDataSource实现自定义分页的心得总结,几种分页方法的性能对比
ASP.NET Ajax 和ASP.NET 2.0 的登陆控件相冲突的问题的讨论
用ObjectDataSource实现自定义分页的心得总结
在VS.NET 2003中使用.ashx进图片及文件的传送和读取
使用XMLHttp在页面间传送参数
解决IE在客户端使用ADODB.Stream不能创建对象成功的方法
最新IT新闻:
[译稿]微软将 jQuery IntelliSense整合到Visual Studio
微软:不裁员也不削减研发开支
2008年11月22日科技博客精选
诺基亚将支持Lotus Notes 和黑莓争夺市场
Mozilla公布去年收入报告
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
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(2)
给我留言
查看留言
我参加的小组
jQuery
我参与的团队
ASP.NET AJAX (Atlas)学习(0/1356)
.NetFramework3.0 & 3.5(WCF,WPF,WF)团队(0/611)
Silverlight学习与研究(0/309)
数据库团队(0/321)
随笔分类
(47)
Ajax(11)
ASP.NET(16)
DataBase Others(6)
Microsoft Visual SourceSafe(1)
Oracle(8)
SQL Server(5)
VB Script
随笔档案
(44)
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中文文档
Microsoft patterns & practices
MS Enterprise Library
层叠样式表手册
动态网站制作指南
就爱E书网
无忧视窗
资源中国
个人链接
MSN共享空间
网易相册
友情博客
newwind
VirtualMJ
最新随笔
1. CodeSmith Professional 5.0破解下载地址 注册机 keygen
2. Apache log4net与EntLib Logging Application Block使用心得
3. 用Codesmith写的一个的从SQL Server向Oracle导数据的模板
4. 不能将Session保存在其他机器的state server 中问题的解决
5. 在asp.net程序开发中避免编译就要重新登录系统的小技巧
6. 两块钱搞定本本的发烧问题
7. 在ASP.NET AJAX中防止用户多次提交页面
8. ASP.NET2.0MasterPage使用技巧总结
9. 【续】用ObjectDataSource实现自定义分页的心得总结,几种分页方法的性能对比
10. ASP.NET Ajax 和ASP.NET 2.0 的登陆控件相冲突的问题的讨论
积分与排名
积分 - 72910
排名 - 636
最新评论
1. re: 用Enterprise Library - January 2006 的Data Access Application Block 访问Oracle存储过程心得
谢谢楼主的回复 但......... 1方法被项目经理驳回,说缺乏变通,2方法被客户cut,客户要求不得引用oracleclient,3方法不可能,因为我们不能操作数据库,数据库是客户做好了的 我...
--Bob&xiaobo.liu
2. re: 用Enterprise Library - January 2006 的Data Access Application Block 访问Oracle存储过程心得
1、可以修改EntLib的源代码,将cur_OUT参数改成其他的。 2、用OracleCommand自己添加游标输出参数。 3、另写一个过程来调用客户的过程,自己写的过程用cur_OUT返回结果集 …...
--漂泊雪狼
3. re: 用Enterprise Library - January 2006 的Data Access Application Block 访问Oracle存储过程心得
我也正好碰到这个问题,楼主的解决方法行得通,但客户不太满意,有没其他更好的解决方法呢,cur_OUT参数问题,修改存储过程是不可能啦 这些是客户提供给我们的
--Bob&xiaobo.liu
4. re: 用CodeSmith编写模板导出Oracle中表的数据
TO: amingo CodeSmith从4.1版直接支持Oracle Schema Provider了,无需从上面的地址下载了,你可以直接从 上面下载一个5.0的安装即可。 ...
--漂泊雪狼
5. re: 用CodeSmith编写模板导出Oracle中表的数据
Oracle的提供程序已经下不了了,有的话请发给我。
dpzhoum@dfl.com.cn
--amingo
阅读排行榜
1. GridView/DataGrid单元格不换行的问题(3902)
2. Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!(3251)
3. 用ObjectDataSource实现自定义分页的心得总结(3066)
4. ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript(3065)
5. 使用XMLHttp在页面间传送参数(2997)
评论排行榜
1. Apache log4net与EntLib Logging Application Block使用心得(24)
2. Active Directory如何用C#进行增加、删除、修改、查询用户与组织单位!(22)
3. 用CodeSmith编写模板导出Oracle中表的数据(19)
4. 要Gmail、Orkut邀请的请留下你的邮箱(16)
5. 招聘.NET Web程序员【深圳】(14)