Implementation of ASP.net 2.0 's TreeView client Personalization control

Source: Internet
Author: User

ASP.net 2.0 's TreeView control feature is powerful, but its client control is inferior, this article will explain the TreeView's client implementation principle, and implement two personalization operations:

(1) All nodes are opened and closed;

TreeNode Expand (or Collapse) all

(2) Open only one node (close other sibling nodes).

Just one node expanded (when a client expand one node all other would collaps)

Using Notepad to open the page source code, you can find two script references: code

[Copy to Clipboard] CODE:

<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>

Copy "/webui/webresource.axd?d=raqebcdunup9ius8q3tnew2&t=633300220640000000" to the end of the address bar, download the script, and name it with. JS, and the other same operation. Analyzing the second script file, you can see many client functions of the TreeView, one of the key Treeview_togglenode is the event triggered when the client clicks.

To do personalized operation, you have to start from the Treeview_togglenode incident. We cannot change the. NET encapsulated script, 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 one for the function with the same name).

Treeview_togglenode's original function: Code

[Copy to Clipboard] CODE:

function Treeview_togglenode (data, Index, node, linetype, children) {
var img = node.childnodes[0];
var n Ewexpandstate;
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) {}
Data.expandState.value = data.expandState.value.substring (0, index) + Newexpandsta Te + data.expandState.value.slice (index + 1);
}

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.