DxComboBox<TData, TValue>.ItemTemplate Property
Specifies a template used to display the ComboBox’s items.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public RenderFragment<TData> ItemTemplate { get; set; }
Property Value
Type | Description |
---|---|
RenderFragment<TData> | The template content. |
Remarks
Place HTML markup in the <ItemTemplate>
tag to define custom content for the ComboBox’s items. Use the template’s context
parameter to access a data object and its fields (for instance, you can get the value of a data field).
The following code snippet displays the ComboBox’s items in a card-like view. Each item shows an employee’s first name, last name, photo, and phone number.
@inject NwindDataService NwindDataService
<DxComboBox Data="@Data"
@bind-Value="@Value"
CssClass="cw-480">
<ItemTemplate>
<div class="combobox-item-template">
<img src="@StaticAssetUtils.GetImagePath(GetImageFileName(context))" />
<div class="combobox-item-template-text">
<span>@context.FirstName @context.LastName</span>
<span class="combobox-item-template-employee-phone">@context.HomePhone</span>
</div>
</div>
</ItemTemplate>
</DxComboBox>
@code {
IEnumerable<Employee> Data { get; set; }
Employee Value { get; set; }
protected override async Task OnInitializedAsync() {
Data = await NwindDataService.GetEmployeesAsync();
Value = Data.FirstOrDefault();
}
string GetImageFileName(Employee employee) {
return $"employees/item-template{employee.EmployeeId}.jpg";
}
}
Note
The ItemTemplate
property does not work for a multi-column ComboBox.
See Also