In my ASP.NET application, used Treeview control with check box enabled. In that treeview if i checked treenode want to show different color in specific checked node. see below
foreach (treenode node in treeview.nodes)
{
if (node.checked == true)
{
"change the color of the node"
}
}
i used to check the nodes like this below coding . but no tag to color change of checked nodes
protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
if (e.Node.ChildNodes.Count > 0)
{
CheckAllChildNodes(e.Node, e.Node.Checked);
}
if (e.Node.ChildNodes.Count == 0)
{
CheckAllParentNodes(e.Node);
}
}
private void CheckAllChildNodes(System.Web.UI.WebControls.TreeNode treeNode, bool nodeChecked)
{
foreach (System.Web.UI.WebControls.TreeNode node in treeNode.ChildNodes)
{
node.Checked = nodeChecked;
if (node.ChildNodes.Count > 0)
{
this.CheckAllChildNodes(node, nodeChecked);
}
}
}
private void CheckAllParentNodes(System.Web.UI.WebControls.TreeNode treeNode)
{
if (treeNode.Parent != null)
{
if (treeNode.Checked == false)
{
treeNode.Parent.Checked = false;
CheckAllParentNodes(treeNode.Parent);
}
}
}
Please help me to solve this thing ..
If i understand your question clearly that is a bit tricky, you have to do following steps
1) Set the text of each node of your tree view like this
2) Use following code in code behind