如何在鼠标单击ASP.NET TreeView中的任何一个子项时保持背景颜色?
答案 0 :(得分:0)
对树视图使用treenodedatabound事件并为每个项目添加onclick事件以调用javascript函数来执行任何操作
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
e.Node.Text = "<span onclick='javascript:MyFunction(this);'>Text</span>";
}
或者您可以这样添加项目
Dim deletenode As New TreeNode("<span onclick=""javascript:confirm('Are you sure you want to delete this ?');"">Delete</span>", "0" & dr("ProjectID"))
Js函数样本
MyFunction(sender) {
//using jquery you have the html element (td ) you can get any value from that element based on your senario
//for example you have attribute called x holding the value you want
alert( $(sender).attr("x"));
//or to change the background color
$(sender).css("background-color" , "blue");
}