<%@ 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>
|