ASPxMenuBase.ItemDataBound Event
Occurs after a menu item has been bound to a data source.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v18.2.dll
Declaration
Event Data
The ItemDataBound event's data class is MenuItemEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Item | Gets 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 ASPxMenu.ItemDataBound event handler. To add Html tags to MenuItems, set the ASPxMenu.EncodeHtml property to false.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/aspxmenu-how-to-customize-menuitem-at-runtime-e3623
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxMenu" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxSiteMapControl" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASPxMenu - How to customize MenuItem at runtime</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<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>
</div>
</form>
</body>
</html>