Click here to Skip to main content
15,947,958 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
System.IO.StringWriter sw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

        // Render grid view control.

        // Write the rendered content to a file.
        string renderedGridView = sw.ToString();
        File.WriteAllText(Request.MapPath("~/Account/temp.xls"), renderedGridView);
        htw = new System.Web.UI.HtmlTextWriter(sw);

I used this and got data exported
But delete and edit buttons are still getting displayed in excel sheet
And only one page is getting added...
Updated 5-Feb-13 21:01pm

You Can Check this Article-
Here checkboxes is used but checkboxes are not showing in exported excel sheet-[^]
Share this answer
Share this answer
Member 9644631 6-Feb-13 6:28am    
Thanks for the help...But there is still one problem...
When i try to open it it gives me the error...
The file name you are trying to open is in a different format than specified by extension....
uspatel 7-Feb-13 6:23am    
replace response.addheader

Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx");
Response.Charset = "";
// If you want the option to open the Excel file without saving than
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900