Skip to main content
A newer version of this page is available. .
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

NuGet Package: DevExpress.Web

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.

protected void ASPxButton1_Click(object sender, EventArgs e)
{
    var products = ASPxGridView1.GetSelectedFieldValues("ProductName");
    ASPxLabel1.Text = products[0].ToString();
}

ASPxGridView-GetSelectedFieldValue

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetSelectedFieldValues(String[]) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also