Skip to main content
Tab

ASPxGridView.SortBy(GridViewColumn, Int32) Method

Sorts data in ascending order by the values of the specified data column, and defines the column’s sort priority among columns.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public int SortBy(
    GridViewColumn column,
    int value
)

Parameters

Name Type Description
column GridViewColumn

A grid column.

value Int32

The column’s sort priority.

Returns

Type Description
Int32

The column’s sort priority.

Remarks

When you call the SortBy method, the grid behaves as follows:

  • Keeps the previous sort order and adds the column to the collection of sorted columns.

  • Sets the SortIndex property to the specified sort priority.

  • Sets the column’s SortOrder property to Ascending.

For more information on sorting in the grid, refer to the following topic: ASPxGridView - Sort Data.

<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" KeyFieldName="ProductID">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="1" >
            <EditFormSettings Visible="False" />
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="2" />
        <dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="3" />
        <dx:GridViewDataTextColumn FieldName="UnitsInStock" VisibleIndex="4" />
        <dx:GridViewDataCheckColumn FieldName="Discontinued" VisibleIndex="5" />
        <dx:GridViewDataTextColumn FieldName="UnitsOnOrder" VisibleIndex="6" />
    </Columns>
</dx:ASPxGridView>
protected void Page_Load(object sender, EventArgs e) {
    grid.SortBy(grid.Columns["ProductName"], 0);
    grid.SortBy(grid.Columns["UnitPrice"], 1);
}
See Also