本篇文章给大家分享的是有关ASP.NET中TreeView的作用是什么,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
ASP.NET 2.0 的 TreeView 控件功能虽说强大,但其客户端控制很逊色,本文将讲解 TreeView 的客户端实现原理,并实现两个个性化操作:
(1) 节点的全部打开和关闭;
Client Side Expand/Collapse All Nodes For ASP.NET 2.0 TreeView.
(2) 只打开一个节点(关闭其他兄弟节点)。
Just one expanded node in ASP.NET 2.0 TreeView (When a client expand one node all other will collaps)
用记事本打开页面源代码,可以找到一下两个脚本引用:
<script src="/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2&t=633300220640000000" type="text/javascript"></script> <script src="/WebUI/WebResource.axd?d=JuTdJhq3NM8Jq_RhssAkEg2&t=633300220640000000" type="text/javascript"></script>
将"/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2& amp;t=633300220640000000"拷到地址栏尾,下载脚本,并以 .js 命名,另一个同样操作。分析第二个脚本文件,可以看到TreeView的很多客户端函数,其中关键的一个 TreeView_ToggleNode 就是客户端点击时触发的事件。
要想做个性化的操作,就得从 TreeView_ToggleNode 事件下手。我们无法更改.net封装好的脚本,只有“重写”。所谓的重写就是在原来的函数之后添加一个同名函数(因为js对于同名函数只调用***一个)。
TreeView_ToggleNode 的原函数:
function TreeView_ToggleNode(data, index, node, lineType, children) { var img = node.childNodes[0]; var newExpandState; try { if (children.style.display == "none") { children.style.display = "block"; newExpandState = "e"; if ((typeof(img) != "undefined") && (img != null)) { if (lineType == "l") { img.src = data.images[15]; } else if (lineType == "t") { img.src = data.images[12]; } else if (lineType == "-") { img.src = data.images[18]; } else { img.src = data.images[5]; } img.alt = data.collapseToolTip.replace(/\{0\}/, TreeView_GetNodeText(node)); } } else { children.style.display = "none"; newExpandState = "c"; if ((typeof(img) != "undefined") && (img != null)) { if (lineType == "l") { img.src = data.images[14]; } else if (lineType == "t") { img.src = data.images[11]; } else if (lineType == "-") { img.src = data.images[17]; } else { img.src = data.images[4]; } img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(node)); } } } catch(e) {} datadata.expandState.value = data.expandState.value.substring(0, index) + newExpandState + data.expandState.value.slice(index + 1); }
以上就是ASP.NET中TreeView的作用是什么,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。