Back to Devexpress

ASPxMenuBase.ItemDataBound Event

aspnet-devexpress-dot-web-dot-aspxmenubase-7fa58cca.md

latest4.2 KB
Original Source

ASPxMenuBase.ItemDataBound Event

Occurs after a menu 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 MenuItemEventHandler ItemDataBound
vb
Public Event ItemDataBound As MenuItemEventHandler

Event Data

The ItemDataBound event's data class is MenuItemEventArgs. 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 menu 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 menu 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 menu control’s items to the required data fields.

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

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

Example

This example illustrates how to customize MenuItem in the ItemDataBound event handler. To add Html tags to MenuItems, set the ASPxMenu.EncodeHtml property to false.

aspx
<dx:ASPxMenu ID="ASPxMenu2" runat="server" EncodeHtml="false" DataSourceID="ASPxSiteMapDataSource1"
    OnItemDataBound="ASPxMenu2_ItemDataBound">
</dx:ASPxMenu>
<dx:ASPxSiteMapDataSource ID="ASPxSiteMapDataSource1" runat="server" SiteMapFileName="~/App_Data/Web.sitemap">
</dx:ASPxSiteMapDataSource>
csharp
using DevExpress.Web.ASPxMenu;
using DevExpress.Web.ASPxSiteMapControl;

public partial class _Default : System.Web.UI.Page {
    protected void Page_Load (object sender, EventArgs e) {

    }
    protected void ASPxMenu2_ItemDataBound (object source, DevExpress.Web.ASPxMenu.MenuItemEventArgs e) {
        SiteMapNode node = e.Item.DataItem as SiteMapNode;
        if (node != null) {
            e.Item.Text = "<div><b>" + e.Item.Text + "</b> 
" + node["description"] + "</div>"; // or some another tags like <a href=''>
            e.Item.NavigateUrl = node["url"];
        }
    }
}
aspx
<dx:ASPxMenu ID="ASPxMenu2" runat="server" EncodeHtml="false" DataSourceID="ASPxSiteMapDataSource1"
    OnItemDataBound="ASPxMenu2_ItemDataBound">
</dx:ASPxMenu>
<dx:ASPxSiteMapDataSource ID="ASPxSiteMapDataSource1" runat="server" SiteMapFileName="~/App_Data/Web.sitemap">
</dx:ASPxSiteMapDataSource>
vb
Imports DevExpress.Web.ASPxMenu
Imports DevExpress.Web.ASPxSiteMapControl

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    End Sub
    Protected Sub ASPxMenu2_ItemDataBound(ByVal source As Object, ByVal e As DevExpress.Web.ASPxMenu.MenuItemEventArgs)
        Dim node As SiteMapNode = TryCast(e.Item.DataItem, SiteMapNode)
        If node IsNot Nothing Then
            e.Item.Text = "<div><b>" & e.Item.Text & "</b> 
" & node("description") & "</div>" ' or some another tags like <a href=''>
            e.Item.NavigateUrl = node("url")
        End If
    End Sub
End Class

See Also

DataItem

DataPath

ASPxMenuBase Class

ASPxMenuBase Members

DevExpress.Web Namespace