Skip to content

Commit 3c1af29

Browse files
author
Marin Bratanov
committed
docs(navigation): access data item
1 parent fe53b75 commit 3c1af29

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

controls/navigation/server-side-programming/events/nodedatabound.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ position: 1
1010

1111
# NodeDataBound
1212

13-
##
1413

1514
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).
1615

@@ -26,7 +25,9 @@ The **NodeDataBound** event handler receives two arguments:
2625

2726
1. 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.
2827

29-
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:
28+
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:
29+
30+
>caption Example 1: Modifying a node based on a condition.
3031
3132
````ASPNET
3233
<telerik:RadNavigation runat="server" ID="RadNavigation1" OnNodeDataBound="RadNavigation1_NodeDataBound" />
@@ -49,6 +50,30 @@ Protected Sub RadNavigation1_NodeDataBound(sender As Object, e As NavigationNode
4950
End Sub
5051
````
5152

53+
>caption Example 2: Accessing the Data Item of a node by casting it to the appropriate class.
54+
55+
````C#
56+
protected void RadNavigation1_NodeDataBound(object sender, Telerik.Web.UI.NavigationNodeEventArguments e)
57+
{
58+
//if bound to something like an SqlDataSource
59+
//DataRowView dataSourceRow = (DataRowView) e.Node.DataItem;
60+
61+
//if bound to a custom object, like through an ObjectDataSource
62+
//SiteDataItem is the type of this custom object
63+
//SiteDataItem itm = e.Node.DataItem as SiteDataItem;
64+
}
65+
````
66+
````VB
67+
Protected Sub RadNavigation1_NodeDataBound(sender As Object, e As Telerik.Web.UI.NavigationNodeEventArguments)
68+
'if bound to something like an SqlDataSource
69+
Dim dataSourceRow As DataRowView = DirectCast(e.Node.DataItem, DataRowView)
70+
71+
'if bound to a custom object, like through an ObjectDataSource
72+
'SiteDataItem is the type of this custom object
73+
Dim itm As SiteDataItem = TryCast(e.Node.DataItem, SiteDataItem)
74+
End Sub
75+
````
76+
5277

5378
# See Also
5479

0 commit comments

Comments
 (0)