Skip to main content

DxTagBox<TData, TValue> Class

A TagBox component.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll


public class DxTagBox<TData, TValue> :
    DxComboBoxBase<TData, TValue, TagBoxJSInteropProxy>,

Type Parameters

Name Description

The data item type.


The value type.


The DevExpress TagBox for Blazor (<DxTagBox>) component displays a drop-down window with a list of strings. Users can select multiple items from a list and type text in the editor to filter list items that contain the search string. Users can also use the Up arrow, Down arrow, and Enter keys to navigate to the editor’s items and select them. When a user presses and holds an arrow key, the editor’s window continuously navigates between items.

TagBox Overview

Run Demo: TagBox - Overview

Add a TagBox to a Project

Follow the steps below to add the TagBox component to an application:

  1. Use a DevExpress Project Template to create a new Blazor Server or Blazor WebAssembly application. If you use a Microsoft project template or already have a Blazor project, configure your project to incorporate DevExpress Blazor components.
  2. Add the <DxTagBox></DxTagBox> markup to a .razor file.
  3. Bind the component to data.
  4. Configure the component: customize the layout and appearance of items and tags, add a clear button and placeholder, and so on (see the sections below).

Bind to Data

Use the Data property to bind the TagBox to a strongly typed collection. Initialize this collection in the OnInitialized lifecycle method or before this method is invoked. Use the DataAsync property instead of the Data property if a strongly typed collection is loaded asynchronously (for instance, from an HTTP request).

Use the Values property to specify the component’s selected value/item collection. You can use the @bind attribute to bind the Values property to a data field. Refer to the following topic for details: Two-Way Data Binding.

<DxTagBox Data="@Cities" @bind-Values="@Values"></DxTagBox>

@code {
    IEnumerable<string> Cities = new List<string>() {

    IEnumerable<string> Values { get; set; }

TagBox Bind To Data

The TagBox can detect IQueryable<T> collections and use benefits of the corresponding LINQ query providers (such as Entity Framework).

If you bind the TagBox to a data collection that stores custom objects (IEnumerable<CustomType>), override the object’s Equals method and set the TextFieldName property. This property specifies the custom object’s field name that returns strings to be shown in the TagBox’s drop-down window.

@using BlazorApp.Data

<DxTagBox Data="@Staff.DataSource"

@code {
    IEnumerable<Person> SelectedStaff { get; set; } = new List<Person>() { Staff.DataSource[0] };

TagBox Overview

If the TextFieldName property is not specified, the TagBox’s items are populated with CustomType.ToString() values.

If your data is stored on a remote service and is loaded through a Web API, assign the data type to the component’s T parameter and use the CustomData property to implement data load logic.

Tags, Custom Tags, and List Items

The TagBox’s drop-down window displays a list of items from a bound data source. Once a user selects an item, its text is displayed as a new tag and the item is hidden from the list. To display the selected items in the list, set the HideSelectedItems property to false.

Set the AllowCustomTags property to true to allow users to type tags that are not in the list.

TagBox Overview

<DxTagBox Data="@Cities"

@code {
    IEnumerable<string> Tags = new List<string>() {
        "New York"

    IEnumerable<string> Cities = new List<string>() {

    IEnumerable<string> Values;

Use the Tags property to specify tags in code. You can use the @bind attribute to bind the Tags property to a data field. Refer to the following topic for details: Two-Way Data Binding. If you do not use two-way binding, handle the TagsChanged event to respond to the tag collection’s changes.

The table below lists API members related to the TagBox item collection:




Provides access to the TagBox’s selected value/item collection.


Fires after a collection of selected values changes.


Specifies the data source field that populates values for the TagBox’s items.


Specifies the current state (displayed/hidden) of a drop-down window.


Displays an editor’s drop-down window.

View Example: Use the DxTagBox control as a filter for a Grid column


The TagBox component allows you to use templates to customize the layout and appearance of its items and tags.

Tag Template

Use the TagTemplate property to customize a tag’s appearance. The template’s Context parameter ships with the following properties:

  • IsCustom - Gets a value that specifies whether the processed tag is custom.
  • Text - Gets the tag’s text.
  • DataItem - Gets the tag’s bound data item.
  • RemoveTagAction - Specifies the predefined action that removes the tag.

The code below demonstrates how to customize a tag appearance according to its type and text.

<DxTagBox Data="@DataSource"
          AllowCustomTags ="true"
            <TagTemplate Context="tagInfo">
                    var styleMode = tagInfo.IsCustom ? ButtonRenderStyleMode.Contained: GetModeByID(tagInfo.DataItem.CountryId);
                    var style = tagInfo.IsCustom ? ButtonRenderStyle.Dark : ButtonRenderStyle.Primary;
                    <DxButton RenderStyle="@style"
                        <span @onclick="@tagInfo.RemoveTagAction">&times;</span>

@code {
    List<City> DataSource { get; set; }
    IEnumerable<string> Tags { get; set; }

    ButtonRenderStyleMode GetModeByID(int countryId) {
        switch (countryId) {
            case 0: return ButtonRenderStyleMode.Contained;
            case 1: return ButtonRenderStyleMode.Outline;
            default: return ButtonRenderStyleMode.Text;

    protected override void OnInitialized() {
        DataSource = CityData.Cities;
        Tags = new List<string>() { "Los Angeles", "Tokyo", "Moscow" };

TagBox Template

Run Demo: TagBox - Tag Template

Item Template

The ItemTemplate property allows you to customize the appearance of the TagBox’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 example below demonstrates how to display the TagBox’s items in a card-like view. Each item shows an employee’s first name, last name, photo, and phone number.

@inject NwindDataService NwindDataService
<DxTagBox Data="@Data"
          CssClass="cw-480 item-template-demo">
    <TagTemplate Context="tagInfo">
        <img class="tag-template-employee-photo" src="@StaticAssetUtils.GetImagePath(GetImageFileName(tagInfo.DataItem))" />
        <span class="tag-item-span-pl">@tagInfo.DataItem.FirstName @tagInfo.DataItem.LastName</span>
        <span class="dxbs-btn-group">
            <button @onclick="@tagInfo.RemoveTagAction" class="btn btn-sm dx-btn dxbs-tag-remove-btn dxbs-cmd-btn dx-blazor-clear-button-icon" type="button">
                <svg class="dx-image dx-image-size-14px" role="img">
                    <use href="_content/DevExpress.Blazor/dx-blazor.svg#dx-remove-tag"></use>
        <div class="item-template">
            <img class="item-template-employee-photo" src="@StaticAssetUtils.GetImagePath(GetImageFileName(context))" width="32" height="32" />
            <div class="item-template-text">
                <span class="item-template-employee-first-name">@context.FirstName @context.LastName</span>
                <span class="item-template-employee-home-phone">@context.HomePhone</span>

@code {
IEnumerable<Employee> Data { get; set; }
    IEnumerable<Employee> Values { get; set; }

    protected override async Task OnInitializedAsync() {
    Data = await NwindDataService.GetEmployeesAsync();
    Values = Data.Take(1);

    string GetImageFileName(Employee employee) {
    return $"Employees/item-template{employee.EmployeeId}.jpg";

TagBox - ItemTemplate

Run Demo: TagBox - ItemTemplate

Multiple Columns

The TagBox can display data across multiple columns. To create columns, use DxListEditorColumn objects that include the following options for column customization:

  • FieldName - Specifies the data source field that populates column items.
  • Caption - Specifies the column header.
  • Visible - Specifies the column visibility.
  • VisibleIndex - Specifies the column display order.
  • Width - Specifies the column width.

To format tag values, use the EditFormat property.

<DxTagBox Data="@Staff.DataSource"
          EditFormat="{1} {2}">
    <DxListEditorColumn FieldName="Id" Width="50px" />
    <DxListEditorColumn FieldName="FirstName" Caption="Name"/>
    <DxListEditorColumn FieldName="LastName" Caption="Surname"/>

@code {
    IEnumerable<Person> SelectedStaff { get; set; } = new List<Person>() { Staff.DataSource[0] };

TagBox - Multiple Columns

Run Demo: TagBox – Multiple Columns

Clear Button and Placeholder

Set the ClearButtonDisplayMode property to Auto to show the Clear button when the TagBox has tags. Users can click this button to clear all the displayed tags (set the Tags property to null).

Use the NullText property to display the prompt text (placeholder) in TagBox when its Tags property is set to null.

<DxTagBox NullText="Select countries..."
          ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto" />

@code {
    IEnumerable<Country> SelectedCountries { get; set; }

TagBox Clear Button

Run Demo: TagBox - Clear Button and Placeholder

Filter Data

The TagBox allows you to dynamically filter list items that contain the text typed into the editor. Use the FilteringMode property to specify the filter data criteria (Contains or StartsWith) or disable filtering.

<DxTagBox Data="@Data"

TagBox Filter

Run Demo: TagBox - Filter Modes

Size Modes

Use the SizeMode property to specify a TagBox size. The code below applies different size modes to TagBox components.

<DxTagBox Data="@Staff.DataSource"

<DxTagBox Data="@Staff.DataSource"

<DxTagBox Data="@Staff.DataSource"

@code {
    IEnumerable<Person> SelectedStaff = new List<Person>() { Staff.DataSource[0] };

TagBox - Size modes

For more information, refer to the following topic: Size Modes.

Virtual Scrolling

When virtual scrolling is activated (ListRenderMode is set to Virtual), the TagBox loads data on demand when a user scrolls its items.

<DxTagBox Data="@Strings"

Run Demo: TagBox - Virtual Scrolling

Input Validation

When you add the TagBox to the Blazor’s standard EditForm, you can use the ValidateBy property to validate component tags and values.

The code below uses the ValidateBy property to validate email addresses (custom tags) specified in the TagBox. In this example the following validation settings are specified:

After a user types an email address, the edit box is underlined in red or green: red indicates the editor contains an invalid tag(s) or is empty; green indicates the tags are valid.

<EditForm Model="@recipients" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
    <DataAnnotationsValidator />
        <label for="emails">Recipients:</label>
        <DxTagBox Id="emails"
                  NullText="Select email recipients"
        <ValidationMessage For="@(() => recipients.Data)" />
    <button type="submit">Submit</button>

@code {
    EmailRecipients recipients = new EmailRecipients();

    private void HandleValidSubmit() {
    private void HandleInvalidSubmit() {

TagBox Validation

For more information, refer to the following help topic: Validate Input.

Run Demo: TagBox - Validation

Read-Only State

The TagBox supports a read-only state. Set the ReadOnly property to true to activate this mode.

<DxTagBox Data="@Fruits"

Run Demo: TagBox - Read-Only and Disabled Modes

Use the DropDownWidthMode property to specify the width of the drop-down list. The following values are available:

  • ContentOrEditorWidth (Default) - The list displays item text completely. The minimum list width matches the editor.

    TagBox Content or Editor Width

  • ContentWidth - The list width is equal to the width of the longest list item.

    TagBox Content Width

  • EditorWidth - The list width matches the editor. List items are cut if they do not fit.

    TagBox Editor Width


When the TagBox loads items on demand (ListRenderMode is set to Virtual), the list width can change while users scroll items.

The following code sets the width of the drop-down list to the editor width.

@using BlazorApp.Data

<DxTagBox Data="@Staff.DataSource"

@code {
    IEnumerable<Person> SelectedStaff { get; set; }

Run Demo: TagBox – Drop-Down List Width

Use the DropDownDirection property to specify the direction in which the TagBox’s drop-down window is displayed relative to the input element. The default value is Down. The following code changes the direction to Up:

<DxTagBox Data="@Cities" @bind-Values="@Values" DropDownDirection="DropDownDirection.Up" />

@code {
    IEnumerable<string> Cities = new List<string>() {

    IEnumerable<string> Values { get; set; }



If the editor is close to a browser window’s edge and there is not enough space to display the drop-down window in the specified direction, the drop-down window is displayed in the opposite direction.

HTML Attributes and Events

You can use HTML attributes and events to configure the TagBox.

<DxTagBox Data="@Strings" 

@code {
    void MyFunction(){


If a Blazor application throws unexpected exceptions, refer to the following help topic: Troubleshooting.


Show 12 items
DevExpress.Blazor.Internal.DxEditorBase<TData, DevExpress.Blazor.Internal.JSInterop.TagBoxJSInteropProxy>
DxDataEditorBase<TData, DevExpress.Blazor.Internal.JSInterop.TagBoxJSInteropProxy>
DxResizableEditorBase<TData, DevExpress.Blazor.Internal.JSInterop.TagBoxJSInteropProxy>
DxDropDownBase<TData, DevExpress.Blazor.Internal.JSInterop.TagBoxJSInteropProxy>
DevExpress.Blazor.Internal.DxComboBoxBase<TData, TValue, DevExpress.Blazor.Internal.JSInterop.TagBoxJSInteropProxy>
DxTagBox<TData, TValue>
See Also