Back to Devexpress

ASPxGridView.Selection Property

aspnet-devexpress-dot-web-dot-aspxgridview-7a058693.md

latest3.2 KB
Original Source

ASPxGridView.Selection Property

Gets an object that allows you to access row selection methods.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public GridViewSelection Selection { get; }
vb
Public ReadOnly Property Selection As GridViewSelection

Property Value

TypeDescription
GridViewSelection

An object that contains row selection methods.

|

Remarks

The Selection property returns the GridViewSelection object. It contains methods that allow you to select or deselect data rows, and get information about the current row selection state.

When the row selection changes, the control raises the client-side ClientGridView.SelectionChanged or the server-side ASPxGridBase.SelectionChanged event (based on the ProcessSelectionChangedOnServer property value).

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

aspx
<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>


<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Invert selection state" AutoPostBack="false">
    <ClientSideEvents Click="onButtonClick" />
</dx:ASPxButton>
js
function onButtonClick(s, e) {
    grid.PerformCallback();
}
csharp
protected void gridview_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
    var grid = sender as ASPxGridView;
    var visibleIndex = 0;
    if(grid.Selection.IsRowSelected(visibleIndex)) {
        grid.Selection.UnselectRow(visibleIndex);
    } else {
        grid.Selection.SelectRow(visibleIndex);
    }
}
vb
Protected Sub gridview_CustomCallback(ByVal sender As Object, ByVal e As ASPxGridViewCustomCallbackEventArgs)
    Dim grid = TryCast(sender, ASPxGridView)
    Dim visibleIndex = 0

    If grid.Selection.IsRowSelected(visibleIndex) Then
        grid.Selection.UnselectRow(visibleIndex)
    Else
        grid.Selection.SelectRow(visibleIndex)
    End If
End Sub

See Also

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace