问题描述:
TreeView上传到服务器,预览效果发现节点图片不显示、展开合并功能缺失.
解决办法:
以下是我个人的解决办法,最终的效果实现了,但是还有一点点小遗憾,就是页面上有基于微软的调用js的报错信息。
CheckBox选择JS,代码是网上找的。
<script language="javascript" type="text/javascript">
var Obj_;
document.onclick=function()
{
if(event.srcElement.tagName=="INPUT")
{
Obj_=event.srcElement;
getNextElement(event.srcElement);
}
}
function getNextElement(srcObj)
{
var i=0;
while(srcObj.tagName!="TABLE")
{
srcObj=srcObj.parentNode;
i++;
if(i>20) break;
}
// if(srcObj.nextSibling==null)
{
selectParentNode(srcObj);
return;
}
if(srcObj.nextSibling.tagName=="DIV")
{
var targetObj=srcObj.nextSibling;
selectThem(targetObj);
}
// else if(srcObj.nextSibling.tagName=="TABLE")
// {
// //
// }
selectParentNode(srcObj);
}
function selectThem(targetObj_)
{
var ChexBox_Obj=targetObj_.getElementsByTagName_r("INPUT");
for(var i=0;i<ChexBox_Obj.length;i++)
{
ChexBox_Obj[i].checked=Obj_.checked;
}
}
function selectParentNode(obj)
{
while(obj.parentNode.previousSibling.tagName=="TABLE")
{
//
var parentObj=obj.parentNode;
var ChexBox_brother=parentObj.getElementsByTagName_r("INPUT");
var counter_=0;
for(var i=0;i<ChexBox_brother.length;i++)
{
if(ChexBox_brother[i].checked) counter_++;
}
//
var parentNContiner=obj.parentNode.previousSibling;
var CheckB=parentNContiner.getElementsByTagName_r("INPUT");
CheckB[0].checked=counter_>0?true:false;
obj=parentNContiner;
}
}
</script>
展开、合并JS,网上代码修改
<script language="javascript" type="text/javascript">
function TreeView_ToggleNode(data, index, node, lineType, children) {
var img = node.childNodes[0];
var newExpandState;
try {
if (children.style.display == "none") {
children.style.display = "block";
newExpandState = "e";
img.src = "../../images/parts/tree_folder3.gif";
}
else {
children.style.display = "none";
newExpandState = "c";
img.src = "../../images/parts/tree_folder4.gif";
}
}
catch(e) {}
}
</script>
页面代码:
<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>