自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺談ASP.NET中的TreeView

開發(fā) 后端
本文講解TreeView的客戶端實(shí)現(xiàn)原理,并實(shí)現(xiàn)兩個(gè)個(gè)性化操作,以及介紹所謂的重寫就是在原來(lái)的函數(shù)之后添加一個(gè)同名函數(shù)。

ASP.NET 2.0 的 TreeView 控件功能雖說強(qiáng)大,但其客戶端控制很遜色,本文將講解 TreeView 的客戶端實(shí)現(xiàn)原理,并實(shí)現(xiàn)兩個(gè)個(gè)性化操作:

(1) 節(jié)點(diǎn)的全部打開和關(guān)閉;
Client Side Expand/Collapse All Nodes For ASP.NET 2.0 TreeView.

(2) 只打開一個(gè)節(jié)點(diǎn)(關(guān)閉其他兄弟節(jié)點(diǎn))。
Just one expanded node in ASP.NET 2.0 TreeView (When a client expand one node all other will collaps)
用記事本打開頁(yè)面源代碼,可以找到一下兩個(gè)腳本引用:

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


將"/WebUI/WebResource.axd?d=RAQeBcDUNuP9iuS8q3tNEw2& amp;t=633300220640000000"拷到地址欄尾,下載腳本,并以 .js 命名,另一個(gè)同樣操作。分析第二個(gè)腳本文件,可以看到TreeView的很多客戶端函數(shù),其中關(guān)鍵的一個(gè) TreeView_ToggleNode 就是客戶端點(diǎn)擊時(shí)觸發(fā)的事件。

要想做個(gè)性化的操作,就得從 TreeView_ToggleNode 事件下手。我們無(wú)法更改.net封裝好的腳本,只有“重寫”。所謂的重寫就是在原來(lái)的函數(shù)之后添加一個(gè)同名函數(shù)(因?yàn)閖s對(duì)于同名函數(shù)只調(diào)用***一個(gè))。

TreeView_ToggleNode 的原函數(shù):

  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
責(zé)任編輯:佚名 來(lái)源: IT168
相關(guān)推薦

2011-06-08 11:36:16

ASP.NETrender

2009-07-24 10:52:42

ASP.NET ISA

2009-07-22 16:11:43

ASP.NET AJA

2009-07-20 15:30:11

ASP.NET應(yīng)用

2009-01-16 13:17:16

AjaxASP.NET.NET

2009-08-24 17:27:47

ASP.NET Tre

2009-07-28 18:00:11

ASP.NET程序

2009-08-05 15:29:33

ASP.NET For

2009-07-23 15:44:39

ASP.NET MVC

2009-07-28 17:49:30

ASP.NET定期回收

2009-07-22 13:24:24

ASP.NET MVC

2009-07-28 16:03:23

ASP.NET狀態(tài)服務(wù)

2009-08-10 10:19:47

ASP.NET組件設(shè)計(jì)

2009-07-20 17:12:17

ASP.NET訪問數(shù)據(jù)

2009-07-23 15:24:37

ASP.NET Ima

2011-08-23 10:58:59

2009-07-21 14:16:02

ASP.NET管道優(yōu)化

2009-07-27 16:19:59

ASP.NET報(bào)表控件

2010-05-20 08:50:45

UrlRoutingASP.NET 4.0

2009-07-23 14:47:03

Page_Load方法ASP.NET
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)