Tab

ASPxGridBase.GetSelectedFieldValues(String[]) Method

Returns the values displayed in all selected data items (rows, cards or records).

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

Declaration

public List<object> GetSelectedFieldValues(
    params string[] fieldNames
)

Parameters

Name Type Description
fieldNames String[]

The names of data source fields whose values are returned.

Returns

Type Description
List<Object>

The list of objects that contain values displayed in the selected data items.

Remarks

Use the GetSelectedFieldValues method to get a single column as well as multiple column values of selected rows.

To get keys (including compound key values) of selected rows that were filtered when the grid operates in Server Mode, do the following:

  • Set the ASPxGridBehaviorSettings.SelectionStoringMode property to GridViewSelectionStoringMode.DataIntegrityOptimized.
  • Set a field whose names are sent as inner parameters to the GetSelectedFieldValues method as a key field. If you have assigned a compound KeyFieldName, you can use all the key field names as inner parameters of the GetSelectedFieldValues method.
  • Use key field values to obtain other row values from a database directly, since the GetSelectedFieldValues method does not return non-key values of selected rows in Server mode.

For a single key:

query.FirstOrDefault(q => q.KeyProperty == "MyKeyValue")

For a compound key:

query.FirstOrDefault(q => q.KeyProperty1  == "MyKeyValue1" && q.KeyProperty2 == "MyKeyValue2" && ...)
NOTE
  • The GetSelectedFieldValues property is not in effect if cell merging is enabled.
  • The GetSelectedFieldValues method returns column values only. So, if a grid is bound to a collection of complex objects (for example, KeyFieldName="Product.Category.CategoryName"), create a hidden column for this complex field. The grid does not render hidden columns, but allows you to get their data on the server side.

    MVC approach:

    settings.Columns.Add("SubRegionInfo.ID").Visible = false;
    

    Web Forms approach:

    ASPxGridView1.Columns.Add("SubRegionInfo.ID").Visible = false;
    

The following example illustrates how to use the GetSelectedFieldValues method to obtain the "ProductName" field's value of the ASPxGridView's selected row.