Introduction to TreeView in ASP. NET

Source: Internet
Author: User

Although the TreeView control of ASP. NET 2.0 has powerful functions, its client control is inferior. This article describes the implementation principle of the TreeView client and implements two personalized operations:

(1) Open and Close all nodes;
Client Side Expand/Collapse All Nodes For ASP. NET 2.0 TreeView.

(2) open only one node (close other sibling nodes ).
Just one expanded node in ASP. NET 2.0 TreeView (When a client expand one node all other will collaps)
Use NotePad to open the page source code. You can find two script references:

 
 
  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> 


Set "/WebUI/WebResource. axd? D = RAQeBcDUNuP9iuS8q3tNEw2 & amp; t = 633300220640000000 "copy to the end of the address bar, download the script, and name it in. js. The other operation is the same. After analyzing the second script file, we can see many client functions of TreeView. The key TreeView_ToggleNode is the event triggered when the client clicks.

To perform personalized operations, you must start with the TreeView_ToggleNode event. We cannot change the. net encapsulated script, but only "Rewrite ". The so-called rewrite is to add a function with the same name after the original function because js only calls the last function with the same name ).

The original function of 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. Analysis on TypeResolver of ASP. NET
  3. Define JavaScriptConverter in ASP. NET
  4. How to replace Sys. Services in ASP. NET
  5. Use Profile Service of ASP. NET AJAX

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.