The ultimate solution for Treeview in Asp.net

Source: Internet
Author: User

 

Recently, we are working on the permission module. Interface implementation that includes permissions. Because Microsoft's Treeview control was used to assign permissions, I encountered a refresh issue about TreeView operations that I had discussed on the Internet. With the help of many people and colleagues, finally, the Treeview problem is well solved.
1. Foreground control: expand, contract, Check/UnCheck, and background control: SelectedIndexChanged.
Solution:
Set autopostback to false;
Add <body onload = "initTree ()">
Then write in PageLoad:
String strTreeName = "TreeView1 ";
String strRef = Page. GetPostBackEventReference (TreeView1 );
String strScript = "<script language =" JavaScript ">" + "<! -- "+" Function initTree () {"+" "+ strTreeName +". onSelectedIndexChange = function () {"+" if (event. oldTreeNodeIndex! =
Event. newTreeNodeIndex) "+" this. queueEvent (onselectedindexchange, event. oldTreeNodeIndex +, + event. newTreeNodeIndex); "+" window. setTimeout ("+ strRef. replace ("", "\") + ", 0, JavaScript ); "+"} "+"} "+" // --> "+" </script> ";
Page. RegisterClientScriptBlock ("InitTree", strScript );

2. In the case of CheckBox. After selecting the checkbox on the front-end, refresh it and find that the status of the Checkbox has become chaotic, and some should be lost. This problem is a bug in Microsoft Treeview. htc, and no good solution has been found online before. Yesterday, I found a Niu Ge solved this problem. He improved the htc file and added the effect of parent-child interaction in the checkbox scenario to htc, it is a good news for people who need to implement this function and are not familiar with JS, because it means that you can implement this function without writing any code. Thank you very much. I will give you the http of this article: aspx "> http://blog.csdn.net/cuike519/archive/2005/02/02/278271.aspx

3. You can further customize SelectedIndexChanged. If the fruit tree has three layers, you can click the first layer. The second layer does not carry out Postback, but Postback is only performed when the third layer is selected.
In fact, this is to modify at the first point and expand the conditions sent at onSelectedIndexChange. The code above only determines that if the new node and the old node are not the same node, SelectedIndexChange will be triggered and _ dopostback will be executed, you only need to change the condition to the one you want to control. However, pay attention to the statements after the if statement. if there is no {number followed by the if statement, if you want to add additional conditions, it means conditional execution should be followed by two sentences.

 



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.