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.