TreeView 不刷新取值
本文欢迎转载,但必须在文章显眼处保留原文地址
http://www.cnblogs.com/Ss_Andy/archive/2010/11/14/1877226.html
<asp:TreeView ID="TreeView1" runat="server" ></asp:TreeView>
JS代码
function GetNode() {
if (event.srcElement.innerText == undefined || event.srcElement.innerText.length <= 0){
return true;
}
return true;
}
alert(event.srcElement.innerText); //取得text值
alert(event.srcElement.pathname); //取得value值,有点取巧
return false;
}
cs代码
TreeView1.Attributes.Add("onclick ", "javascript:return GetNode(); ");
TreeNode node = new TreeNode();
node.Text = "A";
node.Value = "1";
node.NavigateUrl = "1"; //设置成和value值一样,方便前台取值,这里有点取巧,不过能解决问题就好拉!
TreeView1.Nodes.Add(node);