aspnet-devexpress-dot-web-dot-gridviewdatacolumn-412a3e53.md
Specifies the column’s sort order.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
[DefaultValue(ColumnSortOrder.None)]
public virtual ColumnSortOrder SortOrder { get; set; }
<DefaultValue(ColumnSortOrder.None)>
Public Overridable Property SortOrder As ColumnSortOrder
| Type | Default | Description |
|---|---|---|
| ColumnSortOrder | None |
The column’s sort order.
|
Available values:
| Name | Description |
|---|---|
| None |
No sorting is applied to a column.
| | Ascending |
Sorts the column in ascending order.
| | Descending |
Sorts the columns in descending order.
|
The SortOrder property allows you to specify the column’s sort order:
When you change the sort order, the control keeps the previous sort settings and applies an additional condition.
When you specify the SortOrder property for a non-sorted column, the control adds this column to the collection of sorted columns and applies the specified sort order to the column.
You can also use the following methods to change or disable the column’s sort order:
SortAscending()Sorts the column in ascending order.SortDescending()Sorts the column in descending order.UnSort()Clears the sorting applied to the column.
For more information on sorting in the grid, refer to the following topic: ASPxGridView - Sort Data.
<dx:ASPxGridView ID="grid" runat="server" KeyFieldName="CustomerID" AutoGenerateColumns="false">
<Columns>
<dx:GridViewDataTextColumn FieldName="ContactName" SortOrder="Ascending" />
<dx:GridViewDataTextColumn FieldName="CompanyName" />
<dx:GridViewDataTextColumn FieldName="City" />
<dx:GridViewDataCheckColumn FieldName="Discontinued" />
<dx:GridViewDataTextColumn FieldName="Country" />
</Columns>
</dx:ASPxGridView>
protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
// Specify the column's sort order in code
var column = (GridViewDataColumn)grid.Columns["Discontinued"];
column.SortIndex = 0;
column.SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
}
Run Demo: ASPxGridView - Customization Dialog (Web Forms)
Run Demo: GridView - Customization Dialog (MVC)
The following code snippets (auto-collected from DevExpress Examples) contain references to the SortOrder property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
asp-net-web-forms-grid-create-report-based-on-grid-layout/CS/WebApplication1/ReportHelper.cs#L126
gb.RepeatEveryPage = shouldRepeatGroupHeadersOnEveryPage;
GroupField gf = new GroupField(groupedColumn.FieldName, groupedColumn.SortOrder == ColumnSortOrder.Ascending ? XRColumnSortOrder.Ascending : XRColumnSortOrder.Descending);
gb.GroupFields.Add(gf);
asp-net-mvc-grid-create-report-based-on-grid-layout/CS/E4755/Models/MVCxGridViewState.cs#L45
FieldName = column.FieldName;
SortOrder = column.SortOrder;
}
asp-net-web-forms-grid-create-report-based-on-grid-layout/VB/WebApplication1/ReportHelper.vb#L128
gb.RepeatEveryPage = shouldRepeatGroupHeadersOnEveryPage
Dim gf As New GroupField(groupedColumn.FieldName,If(groupedColumn.SortOrder = ColumnSortOrder.Ascending, XRColumnSortOrder.Ascending, XRColumnSortOrder.Descending))
gb.GroupFields.Add(gf)
asp-net-mvc-grid-create-report-based-on-grid-layout/VB/E4755/Models/MVCxGridViewState.vb#L122
FieldName = column.FieldName
SortOrder = column.SortOrder
End Sub
See Also