Here is the sample VB.NET code to transfer data to excel on button clicked event
Protected Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
Me.lblMessage.Text = ""
Me.gdvCustomer.AllowPaging = False
Me.gdvCustomer.DataBind()
Dim tw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Page.Response.ContentType = "application/vnd.ms-excel"
Page.Response.AddHeader("content-disposition", "attachment;Customer.xls")
Page.Response.Charset = ""
Page.EnableViewState = False
frm.Attributes("runat") = "server"
Controls.Add(frm)
frm.Controls.Add(gdvCustomer)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
Me.gdvCustomer.AllowPaging = True
End Sub