Client Side Expand/Collapse All Nodes For ASP.NET 2.0 Treeview
2007-07-27 10:31
726 查看
The asp.net treeview provieds a lot of features/functions, one of which is the Expand/Collapse All functionality on the server side. The Treeview Control has got two function for doing just that:
TreeView.ExpandAll(), TreeView.CollapseAll(). But going to server to accomplish such a simple functionality seemed a little odd to me. So, I wrote some javascript to do the same on the client.
Checkout the below script:
function TreeviewExpandCollapseAll(treeViewId, expandAll)
{
var displayState = (expandAll == true ? “none” : “block”);
var treeView = document.getElementById(treeViewId);
if(treeView)
{
var treeLinks = treeView.getElementsByTagName(”a”);
var nodeCount = treeLinks.length;
var flag = true;for(i=0;i<nodeCount;i++)
{
if(treeLinks[i].firstChild.tagName)
{
if(treeLinks[i].firstChild.tagName.toLowerCase() == “img”)
{
var node = treeLinks[i];
var level = parseInt(treeLinks[i].id.substr(treeLinks[i].id.length - 1),10);
var childContainer = GetParentByTagName(”table”, node).nextSibling;if(flag)
{
if(childContainer.style.display == displayState)
{
TreeView_ToggleNode(eval(treeViewId +”_Data”),level,node,’r',childContainer);
}
flag = false;
}
else
{
if(childContainer.style.display == displayState)
TreeView_ToggleNode(eval(treeViewId +”_Data”),level,node,’l',childContainer);
}
}
}
}//for loop ends
}
}//utility function to get the container of an element by tagname
function GetParentByTagName(parentTagName, childElementObj)
{
var parent = childElementObj.parentNode;
while(parent.tagName.toL
4000
owerCase() != parentTagName.toLowerCase())
{
parent = parent.parentNode;
}
return parent;
}
Get Formatted Version Of Above Script
The above script could be used as:
<a href=”javascript:TreeviewExpandCollapseAll(’<%=TreeView1.ClientID%>’, true)”>Expand All</a>
<a href=”javascript:TreeviewExpandCollapseAll(’<%=TreeView1.ClientID%>’, false)”>Collapse All</a>
<asp:TreeView ID=”TreeView1″ …………………
That’s all there is to it.
Hope this is helpful.
pushp
TreeView.ExpandAll(), TreeView.CollapseAll(). But going to server to accomplish such a simple functionality seemed a little odd to me. So, I wrote some javascript to do the same on the client.
Checkout the below script:
function TreeviewExpandCollapseAll(treeViewId, expandAll)
{
var displayState = (expandAll == true ? “none” : “block”);
var treeView = document.getElementById(treeViewId);
if(treeView)
{
var treeLinks = treeView.getElementsByTagName(”a”);
var nodeCount = treeLinks.length;
var flag = true;for(i=0;i<nodeCount;i++)
{
if(treeLinks[i].firstChild.tagName)
{
if(treeLinks[i].firstChild.tagName.toLowerCase() == “img”)
{
var node = treeLinks[i];
var level = parseInt(treeLinks[i].id.substr(treeLinks[i].id.length - 1),10);
var childContainer = GetParentByTagName(”table”, node).nextSibling;if(flag)
{
if(childContainer.style.display == displayState)
{
TreeView_ToggleNode(eval(treeViewId +”_Data”),level,node,’r',childContainer);
}
flag = false;
}
else
{
if(childContainer.style.display == displayState)
TreeView_ToggleNode(eval(treeViewId +”_Data”),level,node,’l',childContainer);
}
}
}
}//for loop ends
}
}//utility function to get the container of an element by tagname
function GetParentByTagName(parentTagName, childElementObj)
{
var parent = childElementObj.parentNode;
while(parent.tagName.toL
4000
owerCase() != parentTagName.toLowerCase())
{
parent = parent.parentNode;
}
return parent;
}
Get Formatted Version Of Above Script
The above script could be used as:
<a href=”javascript:TreeviewExpandCollapseAll(’<%=TreeView1.ClientID%>’, true)”>Expand All</a>
<a href=”javascript:TreeviewExpandCollapseAll(’<%=TreeView1.ClientID%>’, false)”>Collapse All</a>
<asp:TreeView ID=”TreeView1″ …………………
That’s all there is to it.
Hope this is helpful.
pushp
相关文章推荐
- Client Side Expand/Collapse All Nodes For ASP.NET 2.0 Treeview
- Client Side Expand/Collapse All Nodes For ASP.NET 2.0
- Client Side Expand/Collapse All Nodes For ASP.NET 2.0
- 【原】用使用JavaScript展开/折叠TreeView中所有节点(Expand and Collapse All Nodes of asp.net Treeview on the client with javascript)
- 使用JavaScript展开/折叠TreeView中所有节点(Expand and Collapse All Nodes of asp.net Treeview on the client with javascript)
- asp.net 2.0 Microsoft treeview和webctrl_client目录问题
- ASP.NET 2.0 All-In-One Desk Reference For Dummies
- 【原】父子树的选择【全选/不全选】Asp.Net 2.0 Treeview Checkbox Check/Uncheck All script
- Asp.Net 2.0 Treeview Checkbox Check/Uncheck All script
- Asp.net 2.0 Treeview确无刷新示例
- ASP.NET 2.0的导航控件treeview和menu的实例
- 最简单的Asp.Net 2.0 TreeView的Checkbox级联操作
- Microsoft AJAX Library Essentials: Client-side ASP.NET AJAX, 1.0 Explained (Paperback) Jul.2007.eBook-BBL
- ASP.NET.2.0.Everyday.Apps.For.Dummies(Chapter1)
- TreeView 控件与Vs2005(Asp.Net 2.0)作者:NetFetch
- FlyTreeView for ASP.NET 3.2 破解攻略
- FlyTreeView for ASP.NET 3.2 破解攻略
- Source Code for the Built-in ASP.NET 2.0 Providers Now Available for Download !
- asp.net mvc 3 unobtrusive client side validation not working in IE
- 解决asp.net 2.0 中treeview的checkbox级联选择