Aspose.Grid: Export to Excel - initially fails- then works

[Platform: Aspose Grid (Web) (Visual Studio 2005, SQL 2005, Windows XP Pro)]

Greetings -

The first time my users click on a button object labeled ‘Export to Excel’, and select ‘Open’ in the dialog displayed, Excel comes up with an empty spreadsheet. If they close the spreadsheet window, then click on the ‘Export To Excel’ button again, and click the ‘Open’ option again, Excel comes up with the (populated) spreadsheet expected.

Have you encountered this problem before, and if so, how do I solve it? My code is as follows:

// ds = DataSet

// dgA = Aspose Grid

[HTML]

<td style="width: 100px; height: 28px"><asp:Button ID="cmdExportToExcel" runat="server" CausesValidation="False" OnClick="cmdExportToExcel_Click" Text="Export To Excel" Width="123px" /></td>

[Code-Behind]

protected void cmdExportToExcel_Click(object sender, EventArgs e)

{

if (Session["CachedData"] != null)

{

ds = (DataSet)Session["CachedData"];

try

{

string filename = Path.GetTempPath() + Session.SessionID + ".xls";

// Saves to the file.

dgA.WebWorksheets.SaveToExcelFile(filename);

// Sents the file to browser.

Response.ContentType = "application/vnd.ms-excel";

//Adds header.

Response.AddHeader("content-disposition", "attachment; filename=RecallDump_CustomerID=" + Session["CustomerID"].ToString().Trim() + "_" + Common.DateTimeToFileName(DateTime.Now).ToString() + ".xls");

// Writes file content to the response stream.

Response.WriteFile(filename);

// OK.

Response.Flush();

}

catch (Exception _errormessage)

{

Common.ValField("", "", "MO", "", _errormessage.Message.ToString(), this);

}

BindExcelGrid("dgA", ds, 0);

}

}

Thanks,

Eric Christianson

Hi Eric,

Thanks for considering Aspose.

I think you should call the BindExcelGrid method before exporting the grid to a file.

Thank you.