62,046
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function select(pName,cName) {
alert('ParentName:' + pName + ' CurrentName:' + cName);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TreeView ID="tv" runat="server"></asp:TreeView>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeNode tn, tnChild;
tn = new TreeNode();
tn.Text = string.Format("<span onclick=select('','{0}');>rootNode1</span>", "rootNode1");
tn.SelectAction = TreeNodeSelectAction.None;
tnChild = new TreeNode();
tnChild.Text = string.Format("<span onclick=select('{0}','{1}');>childNode1</span>", "rootNode1", "childNode1");
tnChild.SelectAction = TreeNodeSelectAction.None;
tn.ChildNodes.Add(tnChild);
tnChild = new TreeNode();
tnChild.Text = string.Format("<span onclick=select('{0}','{1}');>childNode1</span>", "rootNode1", "childNode2");
tnChild.SelectAction = TreeNodeSelectAction.None;
tn.ChildNodes.Add(tnChild);
tv.Nodes.Add(tn);
tn = new TreeNode();
tn.Text = string.Format("<span onclick=select('','{0}');>rootNode1</span>", "rootNode2");
tn.SelectAction = TreeNodeSelectAction.None;
tnChild = new TreeNode();
tnChild.Text = string.Format("<span onclick=select('{0}','{1}');>childNode1</span>", "rootNode1", "childNode1");
tnChild.SelectAction = TreeNodeSelectAction.None;
tn.ChildNodes.Add(tnChild);
tnChild = new TreeNode();
tnChild.Text = string.Format("<span onclick=select('{0}','{1}');>childNode1</span>", "rootNode1", "childNode2");
tnChild.SelectAction = TreeNodeSelectAction.None;
tn.ChildNodes.Add(tnChild);
tv.Nodes.Add(tn);
}
}