Community discussion forum

ASP.net :downloading gridview content to excel

  • 1 year ago
    Hi , any one help me.. i want to download the current gridview content to excel i 'm able to down load bt the problem is i am getting all the records to excel not the records which are showing in the gridview. and also at the end of the excel it is showing thread was being aborted plz any one help Thanks rose
  • 1 year ago
    hi, Try this: ds = new DataSet(); ds = (DataSet) Session["Data"]; DataGrid dgExport = new DataGrid(); dgExport.DataSource = ds; dgExport.DataBind(); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); dgExport.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); Hope this works for you. Regards, Royal
  • 1 year ago
    Above code will work fine. But i am afraid this will create problem when paging is there in DataGrid.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!