Farshad heidary
Top achievements
Rank 1
Farshad heidary
asked on 28 Jun 2010, 12:07 PM
hi guys
how ican change order of column in grid for expord.
for example i have a grid with 3 column c1 c2 c3
now i wanna show in excel c3 c1 c2
how can i implement that?
how ican change order of column in grid for expord.
for example i have a grid with 3 column c1 c2 c3
now i wanna show in excel c3 c1 c2
how can i implement that?
3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 28 Jun 2010, 01:58 PM
Hello,
Have you tried setting OrderIndex for the columns before exporting the grid?
CS:
-Shinu.
Have you tried setting OrderIndex for the columns before exporting the grid?
CS:
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| RadGrid1.MasterTableView.GetColumn("C2").OrderIndex = 0; |
| RadGrid1.MasterTableView.GetColumn("C1").OrderIndex = 1; |
| RadGrid1.MasterTableView.Rebind(); |
| . . . |
| RadGrid1.MasterTableView.ExportToExcel(); |
| } |
-Shinu.
0
Farshad heidary
Top achievements
Rank 1
answered on 28 Jun 2010, 04:47 PM
it doesn't work :(
0
Hello Farshad,
If you are using the ExcelML export, you could reorder the columns directly in the ExcelMLExportRowCreated event handler::
Kind regards,
Daniel
the Telerik team
If you are using the ExcelML export, you could reorder the columns directly in the ExcelMLExportRowCreated event handler::
protected void RadGrid1_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e){ ReorderColumn(2, 1, e.Row); //ReorderColumn(old index, new index, row object)}Copy Code
private void ReorderColumn(int oldIndex, int newIndex, RowElement row){ if (oldIndex < newIndex) { for (int i = oldIndex; i < newIndex; i++) { var oldCell = row.Cells[i + 1]; row.Cells[i + 1] = row.Cells[i]; row.Cells[i] = oldCell; } } else if (oldIndex > newIndex) { for (int i = oldIndex; i > newIndex; i--) { var oldCell = row.Cells[i - 1]; row.Cells[i - 1] = row.Cells[i]; row.Cells[i] = oldCell; } } for (int cellIndex = 0; cellIndex < row.Cells.Count; cellIndex++) row.Cells[cellIndex].Attributes["ss:Index"] = (cellIndex + 1).ToString();}Kind regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items