Here is the same code to export GridView from C# in ASP.NET
Hope this is usefulprotected void ExportButton_Click(object sender, EventArgs e){Response.AddHeader("content-disposition", "attachment;filename=Contacts.xls");Response.Charset = String.Empty;Response.ContentType = "application/vnd.xls";System.IO.StringWriter sw = new System.IO.StringWriter();System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);ContactsGridView.RenderControl(hw);Response.Write(sw.ToString());Response.End();}