更改选定节点的颜色 [英] Change the color of the Selected Node

查看:111
本文介绍了更改选定节点的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想更改selectednode的前色.我正在使用以下代码::

Hi,

I want to change the forecolor of the selectednode. I am using following code::

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
 {

TreeView1.SelectedNodeStyle.ForeColor = Color.Maroon;

}



但是我有一个问题,假设我有一个状态树,节点为CA,WA,AK,AZ.当我选择CA时,它变为Marron,而当我选择WA时,其变为Marron,但CA变为正常.我希望所有(被选中的)个人都是Marron.


请帮帮我

谢谢

潘卡伊

格式化的代码.请记住在再次发布之前执行此操作.[/EDIT]



But i have a issue suppose i have a tree of State with nodes CA,WA,AK,AZ. When i select CA its becomes Marron and when i select WA its becomes Marron but CA becomes normal. I want all(which are selected) indivually are Marron.


Please help me

Thanks

Pankaj

Formatted code. Please remember to do this before posting again[/EDIT]

推荐答案

单击节点时,它当然会引起回发,从而重置节点.如果您只需要更改颜色,我建议您使用JavaScript处理它,否则您将需要在回发过程中重置所选节点的颜色
When you click the node it of course causes a postback which resets the nodes. If you only need to change the color I would suggest handling it with JavaScript, otherwise you will need to reset the color of the selected nodes during the postback


问题不是因为PostBack不维持viewstate ... ASP.Net应该做得很好,假设您不再再次进行数据绑定.

问题是您要设置"SelectedNodeStyle",而不是当前选定节点的样式.实际上,您不能为特定节点设置样式(ASP.Net TreeView仅具有特定节点组的样式,例如所选节点和父节点).

您将必须呈现自定义TreeNode. 此页面有一个很好的示例,说明了如何进行一些自定义树节点渲染.另外,我不太熟悉如何维护视图状态,但是您可能想研究如何做到这一点,因此不必在每个回发中设置每个先前选择的节点的样式.
The problem is not because of PostBack not maintaining the viewstate... ASP.Net should do that just fine, assuming you don''t databind again.

The problem is that you are setting "SelectedNodeStyle" rather than the style of the currently selected node. In fact, you cannot set the style for particular nodes (the ASP.Net TreeView only has styles for particular groups of nodes, such as the selected node and the parent node).

You will have to render a custom TreeNode. This page has a pretty good example of how to do some custom tree node rendering. Also, I''m not too familiar with maintaining view state, but you may want to look into how to do that so you don''t have to set each previously selected node''s style on each postback.


这篇关于更改选定节点的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆