美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

浅谈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)
用记事本打开页面源代码,可以找到一下两个脚本引用:

 
 
 
  1.  src="/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2&
    t=633300220640000000"
     type="text/javascript"> 
  2.  src="/WebUI/WebResource.axd?d=JuTdJhq3NM8Jq_RhssAkEg2&
    t=633300220640000000"
     type="text/javascript"> 

将"/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2& amp;t=633300220640000000"拷到地址栏尾,下载脚本,并以 .js 命名,另一个同样操作。分析第二个脚本文件,可以看到TreeView的很多客户端函数,其中关键的一个 TreeView_ToggleNode 就是客户端点击时触发的事件。

要想做个性化的操作,就得从 TreeView_ToggleNode 事件下手。我们无法更改.net封装好的脚本,只有“重写”。所谓的重写就是在原来的函数之后添加一个同名函数(因为js对于同名函数只调用***一个)。

TreeView_ToggleNode 的原函数:

 
 
 
  1. function TreeView_ToggleNode(data, index, node, lineType, children) {  
  2. var img = node.childNodes[0];  
  3. var newExpandState;  
  4. try {  
  5. if (children.style.display == "none") {  
  6. children.style.display = "block";  
  7. newExpandState = "e";  
  8. if ((typeof(img) != "undefined") && (img != null)) {  
  9. if (lineType == "l") {  
  10. img.src = data.images[15];  
  11. }  
  12. else if (lineType == "t") {  
  13. img.src = data.images[12];  
  14. }  
  15. else if (lineType == "-") {  
  16. img.src = data.images[18];  
  17. }  
  18. else {  
  19. img.src = data.images[5];  
  20. }  
  21. img.alt = data.collapseToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));  
  22. }  
  23. }  
  24. else {  
  25. children.style.display = "none";  
  26. newExpandState = "c";  
  27. if ((typeof(img) != "undefined") && (img != null)) {  
  28. if (lineType == "l") {  
  29. img.src = data.images[14];  
  30. }  
  31. else if (lineType == "t") {  
  32. img.src = data.images[11];  
  33. }  
  34. else if (lineType == "-") {  
  35. img.src = data.images[17];  
  36. }  
  37. else {  
  38. img.src = data.images[4];  
  39. }  
  40. img.alt = data.expandToolTip.replace(/\{0\}/, TreeView_GetNodeText(node));  
  41. }  
  42. }  
  43. }  
  44. catch(e) {}  
  45. datadata.expandState.value =  data.expandState.value.substring(0, index) + 
    newExpandState + data.expandState.value.slice(index + 1);  

【编辑推荐】

  1. ASP.NET的TypeConverter
  2. 浅析ASP.NET的TypeResolver
  3. ASP.NET中定义JavaScriptConverter
  4. 在ASP.NET中替换Sys.Services的方法
  5. 使用ASP.NET AJAX的Profile Service

网页标题:浅谈ASP.NET中的TreeView
分享路径:http://www.zsjierui.cn/article/ccsoghp.html

免费获取网站建设与品牌策划方案报价

*主要业务范围包括:高端网站建设, 集团网站建设(网站建设网站制作)找网站建设公司就上美图齐众。
提交需求

    联系我们

    028-86922220
  • 手机:13518219792
  • 地址:成都市太升南路288号锦天国际A幢1002号
  • 24小时服务热线:028-86922220

    网站建设服务

  • 网页设计
  • 网站制作
  • 网站开发

    网站推广服务

  • 营销网站建设
  • 百度快速排名
  • 整站网站推广

    网站运维服务

  • 基础维护
  • 网站改版
  • 网站维护

    FOLLOW US

  • 微信二维码

    微信二维码

Copyright © 2025 资阳站青羊区美图齐众设计工作室(个体工商户) 资阳网站建设公司-选网站建设公司美图齐众!专业的网站制作公司!
All Rights Reserved 版权所有 蜀ICP备2025119604号-1