Pagable datagrid (VB.net) : DataGrid « ADO.net Database « ASP.Net






Pagable datagrid (VB.net)

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
  <head><title>DataGrid Paging</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>
           
       








Related examples in the same category

1.Bind data through SqlConnection to asp:DataGrid (VB.net)
2.Bind to two different asp:datagrid (VB.net)
3.asp:datagrid: sort expression (VB.net)
4.Sort asp:datagrid (VB.net)
5.Bind asp:DataGrid to access database (VB.net)
6.Bind Data to asp DataGrid in C#
7.Set asp:datagrid title bar (C#)