save the data of Asp.net DataGrid in excel sheet
Note - GridAllRecord is the name of DataGrid in given code.
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);
GridAllRecord.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();