Click here to Skip to main content
12,245,287 members (51,051 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello everyone,

I have made an application in asp.net in which on click of gridview template field a javascript is called and from that javascript a new popup window is opened(not modal popup window), i have button in that popup window on click of which i have a function of exporting data to excel..everything works fine but the excel is not viewed as downloaded...

Please help here is my code..


protected void btmExport_Click(object sender, EventArgs e)
    {
        //Response.Redirect("DownloadComplaintsExcel.aspx");
        DataSet ds = (DataSet)ViewState["ComplaintDataSet"];
        ExportDetails(ds.Tables[0]);
    }
 public void ExportDetails(DataTable dt)
    {
        string fileName = "Complaints-" + DateTime.Today.Day.ToString() + "" + DateTime.Today.Month.ToString() + "" + DateTime.Today.Year.ToString();
        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.ContentType = "application/vnd.ms-excel";
        response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\".xls");
       
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        DataGrid dg = new DataGrid();
        dg.DataSource = dt;
        dg.DataBind();
        dg.RenderControl(htw);
        response.Write(sw.ToString());
        response.End();
    }

Please help..

Regards,
Krunal
Posted 28-Sep-12 2:12am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try this
check out[^]
may be help this.
  Permalink  
Comments
chetan virkar 1-Oct-12 0:15am
   
hi krunal,
its good na
that solution is working
then for what problem
you need help...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hello,you can find something useful in below article:
9 Solutions to Export Data to Excel for ASP.NET[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Was not working in Popup so i have opened the page in new tab.. and started working..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100