Skip to main content

ASPxClientGridView.GetSelectedFieldValues(fieldNames, onCallback) Method

Returns the values of the specified fields within selected rows.

Declaration

GetSelectedFieldValues(
    fieldNames: string,
    onCallback: ASPxClientGridViewValuesCallback
): void

Parameters

Name Type Description
fieldNames string

The names of data source fields.

onCallback ASPxClientGridViewValuesCallback

The JavaScript function that gets the list of row values as a parameter.

Remarks

The GetSelectedFieldValues method sends a callback to the server to obtain the specified field values and passes them back to the client. Then it calls the onCallBack function that gets the values as a parameter.

To get the field values of selected rows on the server, call the ASPxGridBase.GetSelectedFieldValues(System.String[]) method.

Limitations

  • When cell merge is enabled, the GetSelectedFieldValues method is not in effect.

Web Forms Example

Run Demo: ASPxGridView - Using Checkboxes

ASPxGridView - GetSelectedFieldValues

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" KeyFieldName="CustomerID"
    AutoGenerateColumns="false">
    <Columns>
        <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" />
        <dx:GridViewDataTextColumn FieldName="ContactName" VisibleIndex="1" />
        <%--...--%>
        <dx:GridViewDataTextColumn FieldName="Country" VisibleIndex="6" />
    </Columns>
    <SettingsBehavior AllowSelectSingleRowOnly="true" />
    <ClientSideEvents SelectionChanged="grid_SelectionChanged" />
</dx:ASPxGridView>
<dx:ASPxMemo ID="ASPxMemo1" ClientInstanceName="memo" runat="server" Height="50px" Width="50%">
</dx:ASPxMemo>
function grid_SelectionChanged(s, e) {
    s.GetSelectedFieldValues("ContactName;Country", GetSelectedFieldValuesCallback);
}
function GetSelectedFieldValuesCallback(values) {
    for (var i = 0; i < values.length; i++) {
        memo.SetText("ContactName: " + values[i][0] + "; Country: " + values[i][1]);
    }
}

MVC Example

Run Demo: GridView - Row Selection (MVC)

@Html.DevExpress().ListBox(settings => {
    settings.Name = "SelectedRows";
    settings.Width = Unit.Percentage(100);
    settings.Height = 250;
    settings.Properties.EnableClientSideAPI = true;
    settings.Theme = "MaterialCompactOrange";
}).GetHtml()
function SelectionChanged(s, e) {
    s.GetSelectedFieldValues("ContactName", GetSelectedFieldValuesCallback);
}
function GetSelectedFieldValuesCallback(values) {
    SelectedRows.BeginUpdate();
    try {
        SelectedRows.ClearItems();
        for (var i = 0; i < values.length; i++) {
            SelectedRows.AddItem(values[i]);
        }
    } finally {
        SelectedRows.EndUpdate();
    }
    $("#count").html(gvRowSelection.GetSelectedRowCount());
}

Get the Values of Complex Fields

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.

Web Forms Example

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

MVC Example

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