Back to Devexpress

NavBarItem.Template Property

aspnet-devexpress-dot-web-dot-navbaritem-f37cf35b.md

latest4.1 KB
Original Source

NavBarItem.Template Property

Gets or sets a template used to display the content of the item.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(null)]
public virtual ITemplate Template { get; set; }
vb
<DefaultValue(Nothing)>
Public Overridable Property Template As ITemplate

Property Value

TypeDefaultDescription
ITemplatenull

An object supporting the System.Web.UI.ITemplate interface which contains the template used for displaying the item’s content.

|

Remarks

Use the Template property to control the contents of the current item. The template defined using this property replaces the content of an item - in particular, the specified image and text of an item.

Note that any style settings defined for the item via the specific properties (such as the ASPxNavBar.ItemStyle or NavBarGroup.ItemStyle) are still in effect for the item whose content is specified through using the Template property.

In order to define the common content for all items within a navbar control, the navbar’s ASPxNavBar.ItemTemplate property can be used. A template for items of a particular group can be specified via the NavBarGroup.ItemTemplate property.

Note

Once a template defined via the Template property is created within a tab control, it is instantiated within a container object of the NavBarItemTemplateContainer type. This container object exposes a set of specific properties to which the template’s child controls can be bound.

Example

This example demonstrates how the ASPxNavBar.GroupDataBound and the ASPxNavBar.ItemDataBound events can be used.

csharp
protected void ASPxNavBar1_GroupDataBound(object source, DevExpress.Web.NavBarGroupEventArgs e) {
     NavBarItem btnItem = e.Group.Items.Add();
     btnItem.Template = LoadControl("ContentTemplate.ascx") as ITemplate;
}
protected void ASPxNavBar1_ItemDataBound(object source, NavBarItemEventArgs e) {
     if (e.Item.Text == "Canon EOS 400D") {
          e.Item.Text = e.Item.Text + " (New model)"; 
     }
}
vb
Protected Sub ASPxNavBar1_GroupDataBound(ByVal source As Object, ByVal e As DevExpress.Web.NavBarGroupEventArgs)
     Dim btnItem As NavBarItem = e.Group.Items.Add()
     btnItem.Template = TryCast(LoadControl("ContentTemplate.ascx"), ITemplate)
End Sub
Protected Sub ASPxNavBar1_ItemDataBound(ByVal source As Object, ByVal e As NavBarItemEventArgs)
     If e.Item.Text = "Canon EOS 400D" Then
          e.Item.Text = e.Item.Text & " (New model)"
     End If
End Sub
aspx
<dx:ASPxNavBar ID="ASPxNavBar1" runat="server" DataSourceID="XmlDataSource1" ongroupdatabound="ASPxNavBar1_GroupDataBound" Width="259px">
     <ItemDataFields TextField="Model" />
</dx:ASPxNavBar>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/NavBarCameras.xml" XPath="Cameras/*">
</asp:XmlDataSource>

See Also

NavBarGroup.ItemTemplate

ASPxNavBar.ItemTemplate

Navigation Bar

NavBarItem Class

NavBarItem Members

DevExpress.Web Namespace