Ah, sorry. That wasn't clear form your question. Put the following in your button click event:
GridView1.DataBind();
StringWriter writer = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
GridView1.RenderControl(htmlWriter);
string path = Server.MapPath("file.xls");
if (!System.IO.File.Exists(path))
{
using (StreamWriter sw = System.IO.File.CreateText(path))
sw.Write(writer.ToString());
}
Make sure you also add this to your code-behind:
public override void VerifyRenderingInServerForm(Control control)
{}
If you need it in VB, try getting it translated at www.codechanger.com