How to set CSS class for some nodes in treeView, on CodeBehind?
How to set CSS class for some nodes in treeView, on CodeBehind?
I want to style some node different, in codebehind.
in my treeView, the parents have a 2Type child. 1type is the same parent type (for ex organizationUnit) and a different type (for exorganMembers). now i want to show this 2type in a deferred style.
source to share
I don't get any nasty comments - it's not really an obvious solution as the TreeNode has no attribute CssClass
and style
(project oversight IMHO).
I had this exact need and solved it by putting the TreeNode text in a field with class and / or style attributes. I say "text" because you think it TreeNode.Text
will be the inner text of the HTML element, but experimenting with it I find that if you set node.Text
in HTML it will (unexpectedly) render as the provided HTML (i.e. sets the innerhtml) ...
So for example
TreeNode tn = new TreeNode("<span style='color:red;'>ABC</span>");
will actually make the text red (as opposed to showing the words "span", etc.). Again, unexpectedly, it works. And again, I was expecting the TreeNode to have (besides CssClass
and / or style
attrs) maybe node.Html
attr to set innerhtml and node.Text
set inttexttext.
Perhaps MSFT assigned the TreeNode to the jr programmer :)
This resolved it for me, hope it helps others.
source to share