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

        // Render grid view control.
        reportGrid.RenderControl(htw);

        // 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...
Posted
Updated 5-Feb-13 21:01pm
v2

 
Share this answer
 
Comments
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
as

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";
You Can Check this Article-
Here checkboxes is used but checkboxes are not showing in exported excel sheet-
http://www.aspdotnet-suresh.com/2011/12/export-selected-gridview-rows-to-excel.html[^]
 
Share this answer
 

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