Hi,
I want to export the datagrid into the excel file.
Please give me the solution as soon as possible.
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Blocked AccountRank #403 · 6.2K reputationPosted Aug 7, 2008, 1:22 AM EDT
For exporting the datagrid into the excel use this code:
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);
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
Happy Coding!!
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Aug 7, 2008, 1:48 PM EDT
Hi Kamal welcome to c-sharpcorner.
You can check out the article by Dipal Choksi in c-sharpcorner
1.http://www.c-sharpcorner.com/UploadFile/DipalChoksi/ExportASPNetDataGridToExcel11222005041447AM/ExportASPNetDataGridToExcel.aspx
or you also can refer the following articles:
1.http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx
2.http://www.codeproject.com/KB/cs/export2excel.aspx
Raj KumarRank #25 · 44.2K reputationPosted Aug 11, 2008, 9:01 PM EDT
See these articles:
Export to Excel is one of the most common functionality required in ASP.NET pages. Users can download the data from the DataGrid into an Excel spreadsheet for offline verification and/or computation.
This article describes how to Export an ASP.Net 2.0 GridView to Excel.
In this version of the article, we will include the handling the Hyperlink columns in the GridView export to Excel and also re-factor our original logic to use more general features of Reflection.