如何更改asp.net(C#)的颜色。如果树节点检查 [英] How to change color in asp.net(c#) . if treenode checked
本文介绍了如何更改asp.net(C#)的颜色。如果树节点检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的ASP.NET应用程序,使用复选框使用树视图控件启用。在这种树状如果我检查的TreeNode想显示不同的颜色特定检查的节点。见下文
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);
}
}
}
请帮我解决这件事情。
推荐答案
如果我明白你的问题清楚,是有点棘手,你必须做以下步骤
If i understand your question clearly that is a bit tricky, you have to do following steps
1)设置你的树视图像这样
1) Set the text of each node of your tree view like this
<asp:TreeNode Text='<font color="Red"> Test Inner 1</font>' Value="1"></asp:TreeNode>
2)按照code code后面
2) Use following code in code behind
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if(Session["lastNode"] != null)
{
TreeNode lastNode = Session["lastNode"] as TreeNode;
TreeNode tn = TreeView1.FindNode(Server.HtmlEncode(lastNode.ValuePath));
tn.Text = tn.Text.Replace(@"color=""Red""", @"color=""Blue""");
}
Session["lastNode"] = TreeView1.SelectedNode;
}
这篇关于如何更改asp.net(C#)的颜色。如果树节点检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文