Maintaining backcolor when mouse click on treeview childs
How to maintain background color when mouse click any one of the children in ASP.NET TreeVie开发者_如何学编程w?
Use the treenodedatabound event for the tree view and add for each item onclick event to call a javascript function to do whatever you want
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
e.Node.Text = "<span onclick='javascript:MyFunction(this);'>Text</span>";
}
or you can add the items in this way
Dim deletenode As New TreeNode("<span onclick=""javascript:confirm('Are you sure you want to delete this ?');"">Delete</span>", "0" & dr("ProjectID"))
Js function sample
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");
}
精彩评论