Back to Devexpress

NavBarGroup.ContentTemplate Property

aspnet-devexpress-dot-web-dot-navbargroup-9bc01dd5.md

latest4.9 KB
Original Source

NavBarGroup.ContentTemplate Property

Gets or sets a template used for displaying the client region’s content of the current group.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

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

Property Value

TypeDefaultDescription
ITemplatenull

An object supporting the System.Web.UI.ITemplate interface which contains the template used for displaying the group’s client region.

|

Remarks

Use the ContentTemplate property to define the content for the client region of the current group. A group’s client region is considered to be an area where group items are displayed - it doesn’t involve the group’s header. The template created using the ContentTemplate property fills the group’s entire client region.

The ContentTemplate property is useful when it is required to display a specific control within a navbar group. Placing a control onto the template container causes the control to be displayed within the group, when it is expanded.

Note that any style settings defined for the group’s client region via the specific properties (such as the ASPxNavBar.GroupContentStyle or NavBarGroup.ContentStyle) are still in effect for the group whose client content is specified using the ContentTemplate property.

The content of client regions of all navbar groups can be defined using the navbar’s ASPxNavBar.GroupContentTemplate property.

Note

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

Example

csharp
public partial class ASPxperience_LoadOnCallback : System.Web.UI.Page {
     protected void LoadGroupContent(NavBarGroup group) {
         Control control = null;
         if(group.Expanded && group.ContentTemplate == null) {
             switch(group.Name) {
                 case "Group1":
                 case "Group2":
                     control = LoadControl("UserControl.ascx");
                     break;
             }
             group.ContentTemplate = control as ITemplate;
         }
     }
     protected void LoadExpandedGroups() {
         for(int i = 0; i < ASPxNavBar1.Groups.Count; i++)
             LoadGroupContent(ASPxNavBar1.Groups[i]);
     }

     protected void Page_Load(object sender, EventArgs e) {
         LoadExpandedGroups();
     }
     protected void ASPxNavBar1_ExpandedChanged(object source, 
     DevExpress.Web.NavBarGroupEventArgs e) {
         LoadGroupContent(e.Group);
     }
}
vb
Partial Public Class ASPxperience_LoadOnCallback
    Inherits System.Web.UI.Page
     Protected Sub LoadGroupContent(ByVal group As NavBarGroup)
         Dim control As Control = Nothing
         If group.Expanded AndAlso group.ContentTemplate Is Nothing Then
             Select Case group.Name
                 Case "Group1", "Group2"
                     control = LoadControl("UserControl.ascx")
             End Select
             group.ContentTemplate = TryCast(control, ITemplate)
         End If
     End Sub
     Protected Sub LoadExpandedGroups()
         For i As Integer = 0 To ASPxNavBar1.Groups.Count - 1
             LoadGroupContent(ASPxNavBar1.Groups(i))
         Next i
     End Sub

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
         LoadExpandedGroups()
     End Sub
     Protected Sub ASPxNavBar1_ExpandedChanged(ByVal source As Object, ByVal e As DevExpress.Web.NavBarGroupEventArgs)
         LoadGroupContent(e.Group)
     End Sub
End Class

See Also

GroupContentTemplate

HeaderTemplate

Navigation Bar

NavBarGroup Class

NavBarGroup Members

DevExpress.Web Namespace