<div id="Div1" style="overflow: scroll; height: 140px;width:638px" > Gridview 在这里 </div> 7、把DataTable里的内容导出到EXCEL,执行代码就行,什么都不用改,什么都不用设置 Private 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