NodeDataBound
The NodeDataBound event occurs for each new node that is added to the Nodes collection of the Navigation when it is bound.This event only occurs if the nodes are loaded from a data source (the DataSource or DataSourceID property is set).
For each node that is added from a data source, the following events occur:
-
A new node is created and added to the Nodes collection.
-
The ItemDataBound event occurs.
The NodeDataBound event handler receives two arguments:
-
The Navigation that is loading the nodes. This argument is of type object, but can be cast to the RadNavigation type.
-
An EventArgs object. This object has an Node property, which provides access to the node that was just bound. This item, in turn, has a DataItem property,which lets you access the item in the data source to which the NavigationNode is being bound.
Use the NodeDataBound event handler to make changes to items as they are bound to the data. For example, you can set custom attributes based on other fields in the DataItem:
Example 1: Modifying a node based on a condition.
<telerik:RadNavigation runat="server" ID="RadNavigation1" OnNodeDataBound="RadNavigation1_NodeDataBound" />
protected void RadNavigation1_NodeDataBound(object sender, NavigationNodeEventArguments e)
{
if (e.Node.Text == "Home")
{
e.Node.Selected = true;
}
}
Example 2: Accessing the Data Item of a node by casting it to the appropriate class.
protected void RadNavigation1_NodeDataBound(object sender, Telerik.Web.UI.NavigationNodeEventArguments e)
{
//if bound to something like an SqlDataSource
//DataRowView dataSourceRow = (DataRowView) e.Node.DataItem;
//if bound to a custom object, like through an ObjectDataSource
//SiteDataItem is the type of this custom object
//SiteDataItem itm = e.Node.DataItem as SiteDataItem;
}