Private Sub toExcel()Sub toExcel(ByVal tb As DataTable)
Dim dgrid As System.Web.UI.WebControls.DataGrid = Nothing
Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
Dim strOur As System.IO.StringWriter = Nothing
Dim htmlWriter As System.Web.UI.HtmlTextWriter = Nothing
If Not IsNothing(tb) Then
context.Response.ContentType = "application/vnd.ms-excel "
context.Response.ContentEncoding = System.Text.Encoding.UTF8
context.Response.Charset = " "
strOur = New IO.StringWriter
htmlWriter = New System.Web.UI.HtmlTextWriter(strOur)
dgrid = New DataGrid
dgrid.DataSource = tb.DefaultView
dgrid.AllowPaging = False
dgrid.DataBind()
dgrid.RenderControl(htmlWriter)
context.Response.Write(strOur.ToString)
context.Response.End()
End If
End Sub ()Sub