Question

I'm porting from ASP.NET GridView to DevExpress AspxGridView, and I'm using the same ObjectDataSource, but now when I click on header it throws:

"The data source 'xxx' does not support sorting with IEnumerable data. Automatic sorting is only supported with DataView, DataTable, and DataSet."

But this worked well for GridView, so I doubt it is really a fault of 'xxx'. On the old gridview paging, and sorting was fine. Now paging still works (when I use "DataSourceForceStandardPaging").

How to make it work with AspxGridView?

Was it helpful?

Solution

You can implement ASPxGridView sorting using custom rules, it is necessary to set the column's Settings.SortMode property to "Custom" and handle the ASPxGridView.CustomColumnSort event (as it illustrated in the corresponding topic). However, the Settings.AllowSort option should not be disabled.

Custom Sorting example:

RepositoryItemHyperLinkEdit hlnkEditor;
private void GridCustomSortTest_Load(object sender, EventArgs e)
{
    string[] months = new string[] { "January", "February", "March", 
        "April", "May", "June", "July", "August", "September", 
        "October", "November", "December" };
    hlnkEditor = new RepositoryItemHyperLinkEdit();
    //hlnkEditor.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;

    grid.DataSource = months;
    grid.RefreshDataSource();
    gridView1.Columns[0].SortMode = DevExpress.XtraGrid.ColumnSortMode.Custom;
    gridView1.Columns[0].ColumnEdit = hlnkEditor;
    gridView1.CustomColumnSort += new DevExpress.XtraGrid.Views.Base.CustomColumnSortEventHandler(gridView1_CustomColumnSort);


}

void gridView1_CustomColumnSort(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnSortEventArgs e)
{
    e.Result = Comparer<int>.Default.Compare(e.ListSourceRowIndex1,
       e.ListSourceRowIndex2);

    e.Handled = true;
}

Hope this help..

Edit: For Server side sorting and paging please go through example - Bind a grid to a ObjectDataSource with EnablePaging and there also check the see also links.

More References:
How can I get the grid to sort my ObjectDataSource on the server?
Passing Gridview Paging/Sorting/Grouping/Filtering expressions to business logic Select Methods
ASPxGridView - ObjectDataSource Paging and Filtering
Performance comparison of XPO and Entity Frameworks, and ObjectDataSource

Binding with Large data:
Binding to Data
Binding to Large Data (Database Server Mode)
A possible implementation of IListServer interface to achieve Server Mode functionality

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top