Back to Devexpress

ASPxNavBar.ItemDataBound Event

aspnet-devexpress-dot-web-dot-aspxnavbar-ba5427ba.md

latest4.7 KB
Original Source

ASPxNavBar.ItemDataBound Event

Occurs after an item has been bound to a data source.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event NavBarItemEventHandler ItemDataBound
vb
Public Event ItemDataBound As NavBarItemEventHandler

Event Data

The ItemDataBound event's data class is NavBarItemEventArgs. The following properties provide information specific to this event:

PropertyDescription
ItemGets an item object related to the event.

Remarks

The ItemDataBound event is raised for each item after it’s data bound to the corresponding data from the specified data source. This event enables you to customize settings of the related item before it is finally rendered. Handling the ItemDataBound event correctly you can, for example, implement a custom logic to dynamically map properties of a navbar control’s items to the required data fields.

The processed navbar item can be accessed by using the NavBarItemEventArgs.Item property of the event’s argument.

If the control functions in unbound mode, the ItemDataBound event isn’t raised.

Example

In the code sample below, the ASPxNavBar control is bound to an XML file using a standard XmlDataSource component. The item/group NavigateUrlField and TextField properties are used to specify the names of data item attributes from which the corresponding item/group settings should be obtained. The ItemDataBound and GroupDataBound events are handled to add corresponding images to items and groups respectively.

The image below shows the result.

csharp
protected void ASPxNavBar1_ItemDataBound(object source, DevExpress.Web.NavBarItemEventArgs e) {
     System.Xml.XmlNode dataItem = ((e.Item.DataItem as IHierarchyData).Item as System.Xml.XmlNode);
     switch (dataItem.Name) {
          case "ctor":
               e.Item.Image.Url = "Images/ctor.gif";
               break;
          case "property":
               e.Item.Image.Url = "Images/property.gif";
               break;
          case "method":
               e.Item.Image.Url = "Images/method.gif";
               break;
          case "event":
               e.Item.Image.Url = "Images/event.gif";
               break;
     }
}

protected void ASPxNavBar1_GroupDataBound(object source, DevExpress.Web.NavBarGroupEventArgs e) {
     e.Group.HeaderImage.Url = "Images/class.gif";
}
vb
Protected Sub ASPxNavBar1_ItemDataBound(ByVal source As Object, ByVal e As DevExpress.Web.NavBarItemEventArgs)
     Dim dataItem As System.Xml.XmlNode = (TryCast((TryCast(e.Item.DataItem, IHierarchyData)).Item, System.Xml.XmlNode))
     Select Case dataItem.Name
          Case "ctor"
               e.Item.Image.Url = "Images/ctor.gif"
          Case "property"
               e.Item.Image.Url = "Images/property.gif"
          Case "method"
               e.Item.Image.Url = "Images/method.gif"
          Case "event"
               e.Item.Image.Url = "Images/event.gif"
     End Select
End Sub

Protected Sub ASPxNavBar1_GroupDataBound(ByVal source As Object, ByVal e As DevExpress.Web.NavBarGroupEventArgs)
     e.Group.HeaderImage.Url = "Images/class.gif"
End Sub
aspx
<dx:ASPxNavBar ID="ASPxNavBar1" runat="server" DataSourceID="XmlDataSource1" 
     onitemdatabound="ASPxNavBar1_ItemDataBound" 
     ongroupdatabound="ASPxNavBar1_GroupDataBound">
     <GroupDataFields NavigateUrlField="HelpUrl" TextField="Title" />
     <ItemDataFields NavigateUrlField="HelpUrl" TextField="Title" />
</dx:ASPxNavBar>

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/TreeView/HelpNav.xml" XPath="/namespace/*">
</asp:XmlDataSource>

See Also

GroupDataBound

DataItem

DataPath

Navigation Bar

ASPxNavBar Class

ASPxNavBar Members

DevExpress.Web Namespace