user1438082
user1438082

Reputation: 2748

Change added treenode backcolor to red

Seems a fairly simple request but i have not found a solution. I've programatically added a root node to an asp.net treeview control. I want to change that node and only that node back color to red.

C# asp.net code please anyone? My code to add the node is below. thanks,

Damo

TreeNode onjParent = new TreeNode(ItemShouldExist, ItemShouldExist);                             
onjParent.PopulateOnDemand = true;
TreeViewAddItems.Nodes.Add(onjParent);
onjParent.Checked = true;

Upvotes: 0

Views: 1703

Answers (1)

Hanlet Escaño
Hanlet Escaño

Reputation: 17380

This adds 10 nodes to a Treeview, and only node 4 has red background.

protected void Page_Load(object sender, EventArgs e)
{
    for (int i = 0; i < 10; i++)
    {
        if (i == 4)
            this.TreeView1.Nodes.Add(new TreeNode() { Text = "<span style='background-color:red'>Node_" + i + "</span>", Value = i.ToString() });
        else
            this.TreeView1.Nodes.Add(new TreeNode() { Text = "Node_" + i, Value = i.ToString() });
    }
}

Edit: Changed font color to background. Good luck!

Upvotes: 4

Related Questions