GridViewDataColumn.SortIndex Property

Gets or sets the column's position among sorted columns.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll


public int SortIndex { get; set; }
Public Property SortIndex As Integer

Property Value

Type Default Description


An integer value that specifies the zero-based column's index among sorted columns. -1 if data is not sorted by this column.


The ASPxGridView allows data sorting by multiple columns. Once a column is sorted, it is automatically added to the collection of sorted columns. If no columns were previously sorted, the column becomes the only element in the collection and gets the 0 sort index. If sorting by one more columns, the newly sorted column is appended to the collection and gets the 1 index, etc.

When data is sorted by multiple columns, you can change the position (order) of sorted columns using the SortIndex property. Note that changing the sorted columns position changes order of data rows.

Setting the SortIndex property to a non-negative integer, the column is added to the sorted columns list. The column's GridViewDataColumn.SortOrder property is automatically set to ColumnSortOrder.Ascending. Setting a column's SortIndex property value to -1 cancels data sorting by this column.

Sorting is allowed if the ASPxGridBehaviorSettings.AllowSort property is set to true.


The following example illustrates how to use the SortIndex property.

Web Forms approach:


For a full example, see the ASPxGridView - Customization Dialog demo.

<dx:ASPxGridView ID="Grid" runat="server" DataSourceID="ProductsDataSource" 
    EnableRowsCache="false" Width="100%">
        <dx:GridViewDataTextColumn FieldName="ProductName">
            <Settings AutoFilterCondition="Contains" />
        <dx:GridViewDataComboBoxColumn FieldName="CategoryID" Caption="Category Name" SortIndex="0" SortOrder="Ascending" AdaptivePriority="1">
            <PropertiesComboBox DataSourceID="CategoriesDataSource" ValueField="CategoryID" TextField="CategoryName" ValueType="System.Int32" />
            <Settings AllowHeaderFilter="True" AllowAutoFilter="False" SortMode="DisplayText" />
            <SettingsHeaderFilter Mode="CheckedList" />

MVC approach:


For a full example, see the GridView - Customization Dialog demo.

@Html.DevExpress().GridView(settings => {
    settings.Name = "GridView";
    settings.SettingsCustomizationDialog.Enabled = true;
    settings.Columns.Add(c => {
        c.FieldName = "ProductName";
        c.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
    settings.Columns.Add(c => {
        c.FieldName = "CategoryID";
        c.Caption = "Category Name";
        c.SortIndex = 0;
        c.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
        c.AdaptivePriority = 1;
        c.Settings.AllowHeaderFilter = DefaultBoolean.True;
        c.Settings.AllowAutoFilter = DefaultBoolean.False;
        c.Settings.SortMode = DevExpress.XtraGrid.ColumnSortMode.DisplayText;
        c.SettingsHeaderFilter.Mode = GridHeaderFilterMode.CheckedList;
        c.EditorProperties().ComboBox(cb => {
            cb.DataSource = NorthwindDataProvider.GetCategories();
            cb.TextField = "CategoryName";
            cb.ValueField = "CategoryID";
            cb.ValueType = typeof(int);
See Also