鼠标单击treeview子项时保持背景色

时间:2010-02-18 05:58:54

标签: asp.net

如何在鼠标单击ASP.NET TreeView中的任何一个子项时保持背景颜色?

1 个答案:

答案 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"); 

}