Hello friends,
I have a task to download a gridview data to excel as it is shown in gridview.
I did this and the problem is that when the download is complete, I need to close the window as it is literally blank.
I can either show a message and button to close the window but anyhow I have to close the window.
Please help. I have code something like this.
if (dt.Rows.Count > 0)
{
int RowsCount = dt.Rows.Count;
System.Random rd = new System.Random(DateTime.Now.Millisecond);
int MyValue = rd.Next(1000000, 99999999);
sUniqueName = MyValue.ToString();
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IRange cells = workbook.Worksheets[0].Cells;
#region Formatting Upper Table Datas
#endregion
var timeUnit = dt.Rows[0]["ContractTimeUnit"].ToString();
var lineItemTotal = dt.Rows[0]["LineItemTotal"].ToString();
cells.CopyFromDataTable(dt, SpreadsheetGear.Data.SetDataFlags.None);
string filename = string.Format("{0}-{1}-{2}", "CustomUpdatesFromASP.aspx.cs", DateTime.Now.ToString("MM-dd-yy"), sUniqueName);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".xls");
workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.Excel8);
Response.End();
}
After the
Response.End()
i.e. after the download is complete, I tried to use javascript to close the window but it did not work.
the javascript function I used after
Response.End()
is something like this.
ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow", "javascript:window.close();", true);
Please help me with this situation.
Thanks