问题描述:
TreeView上传到服务器,预览效果发现节点图片不显示、展开合并功能缺失.
解决办法:
以下是我个人的解决办法,最终的效果实现了,但是还有一点点小遗憾,就是页面上有基于微软的调用js的报错信息。
CheckBox选择JS,代码是网上找的。
1 <script language="javascript" type="text/javascript"> 2 var Obj_; 3 document.onclick=function() 4 { 5 if(event.srcElement.tagName=="INPUT") 6 { 7 Obj_=event.srcElement; 8 getNextElement(event.srcElement); 9 } 10 } 11 function getNextElement(srcObj) 12 { 13 var i=0; 14 while(srcObj.tagName!="TABLE") 15 { 16 srcObj=srcObj.parentNode; 17 i++; 18 if(i>20) break; 19 } 20 // 21 22 if(srcObj.nextSibling==null) 23 { 24 selectParentNode(srcObj); 25 return; 26 } 27 if(srcObj.nextSibling.tagName=="DIV") 28 { 29 var targetObj=srcObj.nextSibling; 30 selectThem(targetObj); 31 } 32 // else if(srcObj.nextSibling.tagName=="TABLE") 33 // { 34 // // 35 // } 36 selectParentNode(srcObj); 37 } 38 function selectThem(targetObj_) 39 { 40 var ChexBox_Obj=targetObj_.getElementsByTagName_r("INPUT"); 41 for(var i=0;i<ChexBox_Obj.length;i++) 42 { 43 ChexBox_Obj[i].checked=Obj_.checked; 44 } 45 } 46 function selectParentNode(obj) 47 { 48 while(obj.parentNode.previousSibling.tagName=="TABLE") 49 { 50 // 51 var parentObj=obj.parentNode; 52 var ChexBox_brother=parentObj.getElementsByTagName_r("INPUT"); 53 var counter_=0; 54 for(var i=0;i<ChexBox_brother.length;i++) 55 { 56 if(ChexBox_brother[i].checked) counter_++; 57 } 58 // 59 var parentNContiner=obj.parentNode.previousSibling; 60 var CheckB=parentNContiner.getElementsByTagName_r("INPUT"); 61 CheckB[0].checked=counter_>0?true:false; 62 obj=parentNContiner; 63 } 64 } 65 </script>
展开、合并JS,网上代码修改
1 <script language="javascript" type="text/javascript"> 2 function TreeView_ToggleNode(data, index, node, lineType, children) { 3 var img = node.childNodes[0]; 4 var newExpandState; 5 try { 6 if (children.style.display == "none") { 7 children.style.display = "block"; 8 newExpandState = "e"; 9 img.src = "../../images/parts/tree_folder3.gif"; 10 } 11 else { 12 children.style.display = "none"; 13 newExpandState = "c"; 14 img.src = "../../images/parts/tree_folder4.gif"; 15 } 16 } 17 catch(e) {} 18 } 19 </script>
页面代码:
1 <asp:TreeView ID="TreeView_1" ShowCheckBoxes="all" runat="server" ShowExpandCollapse="true" CollapseImageUrl="~/images/parts/tree_folder3.gif" ExpandImageUrl="~/images/parts/tree_folder4.gif" NoExpandImageUrl="~/images/parts/tree_folder3.gif"></asp:TreeView>