asp.net树形编程设置节点颜色 [英] asp.net treeview programatically setting node color

查看:104
本文介绍了asp.net树形编程设置节点颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时设置一个TreeView的节点颜色。我填充的TreeView从具有PARENTID,childID的,和描述的集合,并且Ive加入了产权重组presenting我想应用到该节点的颜色。 FWIW源是一个数据库,应用程序是C#。

I want to set the node colors of a treeview at runtime. I populate the treeview from a collection that has the parentid, childid, and description, and Ive added a property representing the color I want applied to the node. FWIW the source is a database, the app is c#.

在一个gridview我使用的RowDataBound()以编程方式影响控制。林不知道如何在TreeView这样做,包括使用哪个事件(数据绑定()?TreeViewDataBound()?)。我的研究一直没有卓有成效至今。一个code段将是非常有用的。

In a gridview I use RowDataBound() to programmatically affect the control. Im not sure how to do so in the treeview, including which event to use (DataBound()? TreeViewDataBound()?). My research has not been fruitful so far. A code snippet would be very useful.

感谢您的帮助。

推荐答案

假设你正在处理的标准TreeView控件,您可以做到这一点的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.treenodedatabound.aspx\"相对=nofollow> TreeDataBound事件。

Assuming you are dealing with the standard TreeView control, you can do this in the TreeDataBound Event.

一个简单的例子(未测试):

A brief example (not tested):

<asp:TreeView runat="server"
    ID="tvMyTreeView"
    OnTreeNodeDataBound="tvMyTreeView_TreeNodeDataBound"
    />

和后端:

protected void tvMyTreeView_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
    DataRowView dr = (DataRowView)e.Node.DataItem;
    e.Node.Style.Add("color", dr["COLOR"].ToString());
}

如果您使用的是Telerik的RadTreeView,那么事件名称的 NodeDataBound

If you are using the Telerik RadTreeView, then the event name is NodeDataBound

您可能必须调整的例子,以更好地满足您的需求,但希望这将让你开始。

You will probably have to tweak the example to better fit your needs, but hopefully this will get you started.

这篇关于asp.net树形编程设置节点颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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