DataGrid的Pagable(VB.NET)实例代码

发布时间:2020-12-15编辑:脚本学堂
本文分享一个vb.net的例子,学习下datagrid中Pageable的用法,有需要的朋友参考下。

vb.net中DataGrid Pageable的实例代码,如下:
 

复制代码 代码示例:

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<html>
  <head><title>DataGrid Paging示例代码-www.jb200.com</title></head>
  <body>
    <h3>DataGrid Paging</h3>
    <form runat="Server">
      <asp:DataGrid id="dgProducts" runat="server"
                    AllowPaging="True"
                    OnPageIndexChanged="GridPageChange"
                    PageSize="8" />
    </form>
  </body>
</html>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
  If Not Page.IsPostBack Then
    DataFiller()
  End IF
End Sub

Sub DataFiller()
  Dim strConnection As String = "Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=java2suser;Password='password';"
  Dim objConnection As New SqlConnection(strConnection)

  Dim strSqlProducts As String = "SELECT ID, FirstName FROM Employee"
  Dim objAdapter As New SqlDataAdapter(strSqlProducts, objConnection)

  Dim objDataSet As New DataSet()
  objAdapter.Fill(objDataSet, "Employee")

  dgProducts.PagerStyle.NextPageText = "Next"
  dgProducts.PagerStyle.PrevPageText = "Previous"

  dgProducts.DataSource = objDataSet.Tables.Item("Employee")
  dgProducts.DataBind()
End Sub

Sub GridPageChange(S As Object, E As DataGridPageChangedEventArgs)
  dgProducts.CurrentPageIndex = E.NewPageIndex
  DataFiller()
End Sub
</script>