Back to Devexpress

ASPxNavBar.GroupDataBound Event

aspnet-devexpress-dot-web-dot-aspxnavbar-5a3dba94.md

latest4.7 KB
Original Source

ASPxNavBar.GroupDataBound Event

Occurs after a group has been bound to a data source.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event NavBarGroupEventHandler GroupDataBound
vb
Public Event GroupDataBound As NavBarGroupEventHandler

Event Data

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

PropertyDescription
GroupGets a group for which the event is fired.

Remarks

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

The processed navbar group can be accessed by using the NavBarGroupEventArgs.Group property of the event’s argument.

If the control functions in unbound mode, the GroupDataBound 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

ItemDataBound

DataItem

DataPath

Navigation Bar

ASPxNavBar Class

ASPxNavBar Members

DevExpress.Web Namespace