Skip to main content

GridViewSelection.IsRowSelectedByKey(Object) Method

Indicates whether the specified row is selected.

Namespace: DevExpress.Web.Data

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public bool IsRowSelectedByKey(
    object keyValue
)

Parameters

Name Type Description
keyValue Object

The key value of the row.

Returns

Type Description
Boolean

true if the specified row is selected; otherwise, false.

Remarks

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

The code sample below gets the current selection state of the row with the specified key value and changes it.

<dx:ASPxGridView ID="gridview" ClientInstanceName="grid" runat="server" AutoGenerateColumns="False"
    KeyFieldName="ProductID" OnCustomCallback="gridview_CustomCallback">
    <Columns>
        <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" />
        <%--...--%>
    </Columns>
</dx:ASPxGridView>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Change selection state" AutoPostBack="false">
    <ClientSideEvents Click="onButtonClick" />
</dx:ASPxButton>
function onButtonClick(s, e) {
    grid.PerformCallback();
}
protected void gridview_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
    var grid = sender as ASPxGridView;
    var rowKey = 6;
    if(grid.Selection.IsRowSelectedByKey(rowKey)) {
        grid.Selection.UnselectRowByKey(rowKey);
    } else {
        grid.Selection.SelectRowByKey(rowKey);
    }
}

Get the Selection State of the Row Specified by the Composite Key Value

<dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" KeyFieldName="ProductID;ProductName">
</dxASPxGridView>
grid.Selection.IsRowSelectedByKey("2|Chang");
See Also