Skip to main content

DxListBox<TData, TValue>.DataAsync Property

Specifies an asynchronous function that returns List Box data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

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

Property Value

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

A function that returns List Box data.

Remarks

Use the DataAsync property to bind the List Box 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 List Box 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.

CancellationToken

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

<DxListBox DataAsync="@GetForecastAsync"
           TextFieldName="@nameof(WeatherForecast.Summary)"
           @bind-Values="values"/>

@code {
    private IEnumerable<WeatherForecast> forecasts;
    private IEnumerable<WeatherForecast> values;

    Task<IEnumerable<WeatherForecast>> GetForecastAsync(CancellationToken cancellationToken) {
        return ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
    }
}

ListBox Sample Data

If you bind the List Box to a data collection that stores custom objects (IEnumerable<CustomType>), override the object’s Equals and GetHashCode() methods. Otherwise, the List Box items are populated with CustomType.ToString() values.

@using BlazorApp.Data

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

@code {
    IEnumerable<Person> Values { get; set; } = Staff.DataSource.Take(2);
}

ListBox CustomObject

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.

Implements

DevExpress.Blazor.IListEditorBase<TData, TValue>.DataAsync
See Also