Just Copy and Paste
protected void Button2_Click(object sender, System.EventArgs e)
{
Response.Clear();
// Dim FileName As String = TextBox6.Text
Response.AddHeader("content-disposition", "attachment;filename=Members.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/Members.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
}