关于treeview的问题,能了两天了,还是没有能出来
列表如下:
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
我想,当我选择某个节点时,就可以返回当前节点的路径,如:
当我选择ccc后,应该返回aaa-> bbb-> ccc,应该如何做?
[解决办法]
js是可以取到上层节点的值的,写了一个demo
<asp:TreeView ID= "TreeView1 " runat= "server " ShowLines= "True " onclick= "javascript:return showpath() ">
<Nodes>
<asp:TreeNode Text= "New Node1 " Value= "New Node1 ">
<asp:TreeNode Text= "New Node2 " Value= "New Node2 ">
<asp:TreeNode Text= "New Node3 " Value= "New Node3 "> </asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text= "New Node4 " Value= "New Node4 "> </asp:TreeNode>
</Nodes>
</asp:TreeView>
<script type= "text/javascript ">
function showpath()
{
var obj = event.srcElement;
var hrefid = obj.id;
var num = hrefid.replace( 'TreeView1t ', ' ');
var result = new Array();
result.push(obj.innerText);
for(var j=num-1;j> =0;j--)
{
var up = document.getElementById( "TreeView1t "+j);
if(getlayer(up) <getlayer(obj) && getlayer(up)> =2 )
{
result.push(up.innerText);
}
}
var layers = ' ';
for(var k=result.length-1;k> =0;k--)
{
layers += result[k]+ "-> "
}
layers = layers.substring(0,layers.length-2);
window.alert(layers);
return false;
}
function getlayer(obj)
{
return obj.parentElement.parentElement.parentElement.rows[0].cells.length;
}
</script>