DxTagBox<TData, TValue>.DataAsync Property

Specifies an asynchronous function that returns TagBox data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

Declaration

[Parameter]
public Func<CancellationToken, Task<IEnumerable<TData>>> DataAsync { get; set; }

Property Value

Type Description
Func<CancellationToken, Task<IEnumerable<TData>>>

A function that returns TagBox data.

Remarks

Use the DataAsync property to bind the TagBox to a strongly typed collection that is loaded asynchronously (for instance, from an HTTP request). This property allows you to prevent the page with the TagBox from excessive re-rendering.

This property specifies an asynchronous function that returns a Task<IEnumerable<T>> object and accepts a CancellationToken object as a parameter. An exception occurs if you declare the function with an incorrect signature.

@using System.Threading;
@using System.Threading.Tasks;

<DxTagBox DataAsync="@GetDataAsync"
          TData="string"
          TValue="string">
</DxTagBox>

@code {
    IEnumerable<string> Cities = new List<string>() {
        "London",
        "Berlin",
        "Paris",
    };

    public Task<IEnumerable<string>> GetDataAsync(CancellationToken ct = default) {
        return Task.FromResult(Cities);
    }
}

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. It specifies the custom object’s field name that returns strings to be shown in the TagBox’s drop-down window.

@using BlazorApp.Data

<DxTagBox DataAsync="@Staff.GetDataAsync"
          @bind-Values="@SelectedStaff"
          TextFieldName="@nameof(Person.Text)">
</DxTagBox>

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

Otherwise, the TagBox’s items are populated with CustomType.ToString() values.

Use the Data property if a strongly typed collection is loaded synchronously. Use the CustomData property if your data is stored on a remote service and is loaded through a Web API.

See Also