This is a migrated thread and some comments may be shown as answers.

[Solved] Export to excel after server side sort

3 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guido Tapia
Top achievements
Rank 1
Guido Tapia asked on 15 May 2009, 03:47 AM
Hi All,

I'm trying to fix an issue with an export to excel functionality requirement I have.  Basically I need to sort the grid before exporting to excel.  I'm trying this at the moment:

private void OnExportToExcelClicked(object sender, EventArgs e)
{
            grid.MasterTableView.SortExpressions.Clear();
            grid.MasterTableView.SortExpressions.AddSortExpression(new GridSortExpression {FieldName = whateverFieldName, SortOrder = GridSortOrder.Ascending});
            grid.MasterTableView.Rebind();

            grid.MasterTableView.ExportToExcel();
}

However this is not working.

Is there anything I'm missing here?

Thanks

Guido Tapia

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 May 2009, 06:03 AM
Hello Guido,

Try setting the sort expression as shown in the code below and see if it helps:
c#:
 
private void OnExportToExcelClicked(object sender, EventArgs e)  
{  
            GridSortExpression expression = new GridSortExpression();  
            expression.FieldName = "FieldName";  
            expression.SortOrder = GridSortOrder.Ascending;  
            grid.MasterTableView.SortExpressions.Clear();  
            grid.MasterTableView.SortExpressions.AddSortExpression(expression);  
            grid.MasterTableView.Rebind();  
  
            grid.MasterTableView.ExportToExcel();  
}  

Thanks
Princy.
0
Guido Tapia
Top achievements
Rank 1
answered on 17 May 2009, 09:55 PM
I don't know if I'm missing something here, but isn't that exactly the same as my code?

Guido
0
Guido Tapia
Top achievements
Rank 1
answered on 17 May 2009, 10:08 PM
My apologies,

I had forgotten I had implemented custom sorting on this grid. 

Operator error.

Thanks

Guido
Tags
Grid
Asked by
Guido Tapia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Guido Tapia
Top achievements
Rank 1
Share this question
or