Skip to main content

DxGrid.GetDataItemValue(Object, String) Method

Returns the value of the specified field for the specified data item.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public object GetDataItemValue(
    object dataItem,
    string fieldName
)

Parameters

Name Type Description
dataItem Object

The data item whose field value should be returned.

fieldName String

The name of the data field whose value should be returned.

Returns

Type Description
Object

The field value.

Remarks

Call the GetDataItemValue method when the Grid is bound to one of the following data sources:

In other cases, you can cast a data item to a required type and use the {DataItem.FieldName} notation instead. You can also call the GetRowValue(Int32, String) method to get a field value for a data row with the specified visible index.

The following example uses the EntityInstantFeedbackSource and calls the GetDataItemValue method to get the selected data item’s ProductName:

@using Microsoft.EntityFrameworkCore
@using DevExpress.Data.Linq
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="InstantFeedbackSource"
        AllowSelectRowByClick="true"
        SelectionMode="GridSelectionMode.Single"
        @bind-SelectedDataItem="@SelectedDataItem"
        KeyFieldName="ProductId"
        @ref="MyGrid">
    <Columns>
        <DxGridSelectionColumn />
        <DxGridDataColumn FieldName="ProductName" />
        <DxGridDataColumn FieldName="UnitPrice" />
    </Columns>
</DxGrid>

<div style="margin-top: 10px">
    <DxButton Click="OnGetSelectedProductName">Get Selected Product Name</DxButton>
</div>
<div style="margin-top: 10px">
    Selected Product Name: @SelectedProductInfo
</div>

@code {
    EntityInstantFeedbackSource InstantFeedbackSource { get; set; }
    NorthwindContext Northwind { get; set; }
    object SelectedDataItem { get; set; }
    IGrid MyGrid { get; set; }
    string SelectedProductInfo { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        InstantFeedbackSource = new EntityInstantFeedbackSource(e => {
            e.KeyExpression = "ProductId";
            e.QueryableSource = Northwind.Products;
        });
    }

    void OnGetSelectedProductName() {
        SelectedProductInfo = (string)MyGrid.GetDataItemValue(SelectedDataItem, "ProductName");
    }

    public void Dispose() {
        InstantFeedbackSource?.Dispose();
        Northwind?.Dispose();
    }
}

Blazor Grid Get Data Item Value

See Also