Sorry Here is the code below
Partial Class Excel
Inherits System.Web.UI.Page
Protected Sub btExport_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btExport.Click
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Me.Controls.Add(frm)
frm.Controls.Add(GridView1)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
End Sub
End Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Excel.aspx.vb"
Inherits="Excel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btExport" runat="server" OnClick="btExport_Click"
Text="Export" Style="position: relative; z-index: 100;" />
<asp:SqlDataSource ID="dsSearch" runat="server"
ConnectionString="<%$ ConnectionStrings:SipAppConnectionString %>"
SelectCommand="SELECT [DateImaged], [DeviceType] FROM [AllDevices]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="dsSearch"
BackColor="Silver" EmptyDataText="Sorry, your search has come up empty!">
</asp:GridView>
</div>
</form>
Code Behind Page