CSharp Pagable Datagrid (Vb.Net) – ADO.Net Database

<%@ 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 SubSub DataFiller()
  Dim strConnection As String = "Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=w3mentoruser;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 SubSub GridPageChange(S As Object, E As DataGridPageChangedEventArgs)
  dgProducts.CurrentPageIndex = E.NewPageIndex
  DataFiller()
End Sub
</script>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.