hi frds, can anyone help me regarding export a data from gridview to excel,
actually i have a grdview with some template field , like first cell is checkbox and second is select field like that,
so in that aspx page i have a button, when i click a button event i need to open a excel sheet, so can any one help me???
also i tried some of them downloaded from internet and used some , but error occuring , some times unable to open, like error msg im getting,
so plz help me in this?????
Raj KumarPosted Aug 12, 2008, 1:15 AM
private void Button1_Click(object sender, System.EventArgs e)
{
//export to excel
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(dg);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
For more information see these articles:
Muhammad Shahid FarooqPosted Aug 11, 2008, 6:32 PM
Read the following links carefully, this will guide you better:
http://www.codeproject.com/KB/database/ExportDataToExcelUsingCS.aspx
http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx