aspnet-devexpress-dot-web-dot-aspxtreeview-6becc5cd.md
Occurs after a node has been bound to a data source.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event TreeViewNodeEventHandler NodeDataBound
Public Event NodeDataBound As TreeViewNodeEventHandler
The NodeDataBound event's data class is TreeViewNodeEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Node | Gets a node object related to the event. |
The NodeDataBound event is raised for each node after it’s data bound to the corresponding data from the specified data source. This event enables you to customize settings of the related node before it is finally rendered.
The processed node can be accessed by using the TreeViewNodeEventArgs.Node property of the event’s argument.
If the control functions in unbound mode, the NodeDataBound event isn’t raised.
In this code, the ASPxTreeView is bound to an XML file using a standard XmlDataSource component. The ASPxTreeView’s TextField, ImageUrlField, and NavigateUrlField properties are used to specify the names of data item attributes from which the corresponding node settings should be obtained. The NodeDataBound event is handled to change the text style of nodes which represent classes (their text is displayed in bold).
using DevExpress.Web.ASPxTreeView;
using System.Xml;
public partial class TreeView_DataBinding : Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
treeView.DataBind();
treeView.ExpandToDepth(0);
}
}
protected void treeView_NodeDataBound(object source, TreeViewNodeEventArgs e) {
XmlNode dataNode = ((e.Node.DataItem as IHierarchyData).Item as XmlNode);
if (dataNode.Name == "class")
e.Node.TextStyle.Font.Bold = true;
}
}
<dx:ASPxTreeView ID="treeView" runat="server" DataSourceID="XmlDataSource1" AllowSelectNode="true"
OnNodeDataBound="treeView_NodeDataBound" TextField="Title" NavigateUrlField="HelpUrl"
ImageUrlField="NodeTypeImage">
<Images>
<NodeImage Width="16px" Height="16px">
</NodeImage>
</Images>
<Styles>
<NodeImage Paddings-PaddingTop="3px">
</NodeImage>
</Styles>
</dx:ASPxTreeView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/TreeView/HelpNav.xml" XPath="/namespace/*">
</asp:XmlDataSource>
See Also