"RadGrid instance will be bound to all of the 5000 records which is quite memory consuming"
Yes they way you have done it :-)
"Unfortunately there is little that can be done when trying to export large amounts of data"
Why not only bind to the current view and step to the next page and rebind and continue this until all the pages in the grid have been exported. Then you don´t have this issue.
Like this for example:
ExcelFile excelFile = new ExcelFile(); |
MemoryStream Stream = new MemoryStream(); |
ExcelWorksheet ws = excelFile.Worksheets.Add("Worksheetname"); |
|
int CurrentPageIndexBeforeExport = RadGrid1.CurrentPageIndex; |
|
int TotalPageCount = this.RadGrid1.PageCount; |
int PageCounter = 0; |
int ItemCounter = 1; |
for (PageCounter = 0; PageCounter < TotalPageCount; PageCounter++) |
{ |
RadGrid1.CurrentPageIndex = PageCounter; |
this.RadGrid1.Rebind(); |
foreach (GridDataItem Item in RadGrid1.MasterTableView.Items) |
{ |
if (Item is GridDataItem) |
{ |
//Export row to excel |
ws.Cells["A" + ItemCounter.ToString()].Value = Item["Catalogue"].Text; |
//ws.Cells["A" + ItemCounter.ToString()].Style.Font.Weight = ExcelFont.BoldWeight; |
ws.Cells["B" + ItemCounter.ToString()].Value = Item["CoverTitle"].Text; |
ws.Cells["C" + ItemCounter.ToString()].Value = Item["ReportPeriod"].Text; |
ws.Cells["D" + ItemCounter.ToString()].Value = Item["SalesPeriod"].Text; |
ws.Cells["E" + ItemCounter.ToString()].Value = Item["SalesCountry"].Text; |
ws.Cells["F" + ItemCounter.ToString()].Value = Item["ItemsSold"].Text; |
ItemCounter++; |
} |
} |
} |
RadGrid1.CurrentPageIndex = CurrentPageIndexBeforeExport; |
|
|
|
//Saving excel and pushing it out to user |
excelFile.SaveXls(Stream); |
Response.ContentType = "Application/vnd.ms-excel"; |
Response.AddHeader("Content-Disposition", "attachment; filename=" + ExcelName); |
byte[] arrByteExcel = Stream.GetBuffer(); |
Response.AddHeader("content-length", System.Convert.ToString(arrByteExcel.Length)); |
Response.BinaryWrite(arrByteExcel); |
Response.End(); |