treeview可不可以实现这样的效果
treeview的每个treeitem所在的一行,都可以用鼠标点击,并不仅限于treeitem的字上,不知说明白没
------解决方案--------------------<asp:TreeView ID="TreeView1" runat="server" ShowLines="True" onclick="javascript:showline()" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
<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>
</Nodes>
</asp:TreeView>
<script type="text/javascript">
function showline()
{
//从点击行获取最外层table对象
var the_tab = get_Element(event.srcElement,"table");
var cells = the_tab.rows[0].cells.length-1;
//获取最后一列内部html
var html = the_tab.rows[0].cells[cells].innerHTML;
var subhtml = html.substring(html.indexOf('id='),html.length-html.indexOf('id='));
//获取nodeid
var nodeid = subhtml.substring(3,subhtml.indexOf(' '));
var theobj = document.getElementById(nodeid);
var num = nodeid.replace( "TreeView1t"," ");
//数组存放从根结点到现节点的路径
var result= new Array();
result.push(theobj.innerText);
//将父节点text存到result
for(var j=num-1;j >=0;j--)
{
var up = document.getElementById("TreeView1t"+j);
if(getlayer(up) <getlayer(theobj)&&getlayer(up)>=2)
{
result.push(up.innerText);
}
}
//拼接回传参数字符串
var layers = "s";
for(var k=result.length-1;k >=0;k--)
{
layers+=result[k]+'\\';//关键是这里不需要再加转义字符'\'
}
layers = layers.substring(0,layers.length-1);
//将treeview手动postback
__doPostBack('TreeView1',layers);
}
//获取上层节点对象
function get_Element(the_ele,the_tag){
the_tag = the_tag.toLowerCase();
if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
while(the_ele=the_ele.offsetParent){
if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
}
return(null);
}
//获取当前点击行的层数
function getlayer(obj)
{
return obj.parentElement.parentElement.parentElement.rows[0].cells.length;
}
</script>
点击New Node2的左边空白处就可回传