using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;using System.IO;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } //Double click your Button and write the below code to Export Gridview Data to Excel protected void Button1_Click(object sender, EventArgs e) { TextWriter sw = new StreamWriter(@"F:\\ExcelData.xls"); //Getting the Gridview HeaderRow Valuessw.WriteLine(GridView1.HeaderRow.Cells[0].Text+"\t"+GridView1.HeaderRow.Cells[1].Text+"\t" +GridView1.HeaderRow.Cells[2].Text); for (int i = 0; i < GridView1.Rows.Count; i++) { //Getting the Gridview Row values sw.WriteLine(GridView1.Rows[i].Cells[0].Text + "\t " + GridView1.Rows[i].Cells[1].Text + "\t" + GridView1.Rows[i].Cells[2].Text ); } sw.Close();//Don’t Forget to Close the StreamWrtier object. }}