我用GridView将DataTable导出为Excel文件,如何使用其分页功能?
代码如下:
Dim sw As New StringWriter
Dim htw As New System.Web.UI.HtmlTextWriter(sw)
Dim gridview1 As New System.Web.UI.WebControls.GridView
gridview1.AllowPaging = True '设置分页,问题应该出现在这里
gridview1.PageSize = 200 '想每页显示200条
gridview1.Attributes.Add("style", "vnd.ms-excel.numberformat:@")
gridview1.DataSource = Table
gridview1.DataMember = Table.TableName
gridview1.DataBind() '200条以上在此处出错,未将对象引用设置到对象的实例。
gridview1.RenderControl(htw)
Dim str As String = sw.ToString
Try
File.WriteAllText(FileName, str, Encoding.UTF8)
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
End Try