Skip to main content

DxDataGrid<T>.KeyFieldName Property

Specifies the key data field’s name.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll


public string KeyFieldName { get; set; }

Property Value

Type Description

The key field’s name.



The Data Grid was moved to maintenance support mode. No new features/capabilities will be added to this component. We recommend that you migrate to the Grid component.

The Data Grid should be able to identify individual data items when users edit data, select data rows, or expand detail rows in master-detail layouts.

You can specify the key data field in one of the following ways:

  • Define the Data Grid’s KeyFieldName property explicitly.

    @using System.Threading
    @inject WeatherForecastService WeatherForecastService
    <DxDataGrid DataAsync="@LoadDataAsync" KeyFieldName="Id">
    @code {
        async Task<IEnumerable<WeatherForecast>> LoadDataAsync(CancellationToken token) {
            return await WeatherForecastService.GetForecastAsync(DateTime.Now.Date);
  • Mark the key data field with the Key attribute in a data collection. Note the KeyFieldName property takes priority over this attribute.

    using System;
    using System.ComponentModel.DataAnnotations;
    public class WeatherForecast {
        public int Id { get; set; }
        public DateTime Date { get; set; }
        public int TemperatureC { get; set; }
        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
        public string Summary { get; set; }
  • Use the CustomData property and the PrimaryKey array to specify multiple key fields:

    <DxDataGrid T="@WebApiOrder" CustomData="@LoadCustomData">
        @* ... *@
    @code {
        IQueryable<WebApiOrder> _data;
        protected Task<LoadResult> LoadCustomData(DataSourceLoadOptionsBase options, CancellationToken cancellationToken)
            @* ... *@
            options.PrimaryKey = new[] { "Key1", "Key2" };
            return DataSourceLoader.LoadAsync(_data, options, cancellationToken);


The key field’s values should be unique.

If you do not specify the key field name, the standard Equals method is used to compare data items.

Run Demo: Data Grid - Multiple Selection with Optimized Performance

See Also