jeevan mummadi

jeevan mummadi

  • NA
  • 157
  • 0

system out of memory exception occured when data export to excel from grid.

Jun 23 2011 1:44 AM

Hi All,

my grid consist of 40,000+ rows with 22 columns, and i am exporting grid data to excel programtically.
But i am getting system out of memory exception.

I am using this below code to export data from grid.

Code :


Response.Clear();
  int j = 0;
  //Add headers of the exported file
  foreach (Column col in gvJob.Columns)
  {
  if (j > 0)
  {
  Response.Write(",");
  }
  Response.Write(col.HeaderText);
  j++;
  }
  //How add the data from the Grid to exported file
  for (int i = 0; i < gvJob.Rows.Count; i++)
  {
  Hashtable dataItem = gvJob.Rows[i].ToHashtable();
  j = 0;
  Response.Write("\n");
  foreach (Column col in gvJob.Columns)
  {
  if (j > 0)
  {
  Response.Write(",");
  }
  //Response.Write(dataItem[col.DataField].ToString());
  Response.Write(Convert.ToString( dataItem[col.DataField]));
  j++;
  }
  }
  // Send the data and the appropriate headers to the browser 
  Response.AddHeader("content-disposition", "attachment;filename=gvJob.csv");
  Response.ContentType = "text/csv";
  Response.End();
Is there any way to fix this issue, Please Help me.

Regards,
Jeevan.

Answers (1)