Skip to main content

ASPxClientGridView.GetSelectedKeysOnPage Method

Returns the key values of selected rows.

Declaration

GetSelectedKeysOnPage(): any[]

Returns

Type Description
any[]

An array that contains the key values of the rows selected on the current page.

Remarks

For more information on row selection in the grid, refer to the following topic: Selection.

Example

The code sample below calls the client-side GetSelectedKeysOnPage method to count the number of selected rows within the current page and compares it to the number of visible rows.

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" AutoGenerateColumns="False"
    KeyFieldName="ProductID" OnRowDeleting="GridView_RowDeleting">
    <Columns>
        <dx:GridViewCommandColumn ShowSelectCheckbox="true" SelectAllCheckboxMode="Page" VisibleIndex="0" />
        <%--...--%>
    </Columns>
</dx:ASPxGridView>
<div style="margin: 10px 0;">
    <dx:ASPxButton ID="Button" runat="server" Text="Delete selected rows" AutoPostBack="false">
        <ClientSideEvents Click="DeleteSelectedRows" />
    </dx:ASPxButton>
</div>
function DeleteSelectedRows(s, e) {
    var keys = grid.GetSelectedKeysOnPage();
    var rowsCount = grid.GetVisibleRowsOnPage();
    if (keys.length == rowsCount) {
        alert('You cannot delete all rows on a page!');
        grid.UnselectRowsByKey(keys);
    } else {
        if (confirm('Are you sure you want to delete rows with keys: [' + keys.toString() + ']')) {
            alert('Data editing is not allowed in this demo!');
            keys.forEach(function (key, index) {
                grid.DeleteRowByKey(key);
            });
        }
    }
};
protected void GridView_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) {
    e.Cancel = true;
}
See Also