DxGrid.SelectedDataItem Property
In single selection mode, specifies the data item that corresponds to the selected Grid row.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v22.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(null)]
[Parameter]
public object SelectedDataItem { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Object | null | The data item. |
Remarks
Set the SelectionMode property to GridSelectionMode.Single to enable single row selection. A row can be selected and deselected in the following ways:
- A user clicks the row to select it. To enable this functionality, set the AllowSelectRowByClick property to
true
. - A user clicks a radio button in the selection column. To display this column, declare a DxGridSelectionColumn object in the Columns template.
- Call the
Select*
orDeselect*
method. Refer to the Grid’s member table for a list of available methods.
To access the data item that corresponds to the selected row, use the SelectedDataItem
property as follows:
- Implement two-way binding for this property (
@bind-SelectedDataItem
) to specify the initially selected row and automatically update the property value when selection changes. - Use one-way binding for this property and handle the SelectedDataItemChanged event to implement a custom response to selection changes.
When you set the SelectionMode
property to GridSelectionMode.Multiple, use the SelectedDataItems property instead.
The following example allows users to click a row to select it and displays information about the selected row:
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource"
AllowSelectRowByClick="true"
SelectionMode="GridSelectionMode.Single"
@bind-SelectedDataItem="@SelectedDataItem"
KeyFieldName="ProductId">
<Columns>
<DxGridDataColumn FieldName="ProductName" />
<DxGridDataColumn FieldName="UnitPrice" />
<DxGridDataColumn FieldName="QuantityPerUnit" />
<DxGridDataColumn FieldName="UnitsInStock" />
</Columns>
</DxGrid>
<br />
<div>
<p><b>Selected product:</b> @((SelectedDataItem as Product)?.ProductName ?? "(none)")</p>
</div>
@code {
IEnumerable<object> GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
object SelectedDataItem { get; set; }
protected override void OnInitialized() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = Northwind.Products
.ToList();
SelectedDataItem = GridDataSource.FirstOrDefault();
}
public void Dispose() {
Northwind?.Dispose();
}
}
Implements
See Also