Microsoft KB Archive/829142

= How to dynamically page through a large result set in ASP.NET by using SQL Server stored procedures in Visual C# .NET =

Article ID: 829142

Article Last Modified on 8/20/2004

-

APPLIES TO


 * Microsoft ASP.NET 1.0
 * Microsoft ASP.NET 1.1
 * Microsoft SQL Server 7.0 Standard Edition
 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 2000 64-bit Edition
 * Microsoft ADO.NET 1.1
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition

-





IN THIS TASK
 SUMMARY  Methods of implementation Paging by dynamically altering the SQL Query  Create a table schema Create stored procedures

 Create an ASP.NET Web application</li> Populate the database</li> Test dynamic paging</li></ul> </li></ul> </li> REFERENCES</li></ul>

<div class="summary_section">

SUMMARY
This step-by-step article describes how to use SQL stored procedures to dynamically page through a large result set in Microsoft ASP.NET.

back to the top

Methods of implementation
There are three main paging techniques that you can use in ASP.NET to display a limited subset of a result set and to scroll through this limited subset.

These techniques, together with their advantages and disadvantages, are as follows:
 * 1) The first technique is to select the whole result set each time, and to discard the records that you do not want to display. This is the least efficient paging technique.
 * 2) The second technique is useful if the result set is expensive to generate. In this technique, you store the result set (or the primary key values) in a cache, either by using a session variable in the ASP.NET process, or in another table in the database, and then read the appropriate rows from the result set. This storage-intensive technique works best if the result set is rather small because it is a good idea to implement a mechanism to time-out the data. Another disadvantage of this technique is that the data can become stale.
 * 3) The third technique is to dynamically change the query to select only the records that are required for the next page of data. This technique is demonstrated by using the sample code that is presented in this article. The salient features of this technique are as follows:
 * 4) * You can dynamically set the page size.
 * 5) * You can filter the data.
 * 6) * You use stored procedures instead of dynamic SQL to restrict access to the tables.
 * 7) * The result is sorted on multiple fields and not on the primary key.
 * 8) * The sort fields can contain duplicates.

back to the top

Paging by dynamically altering the SQL query
The following sample application illustrates paging through student records that are sorted by student name, last name, first name, and middle initial. The page size can vary between 25, 100, and 500 records.

Note Users with slower connections can select a smaller page size, while those on a local area network (LAN) can select a larger page size.

back to the top

Create a table schema
The following SQL query creates the basic table schema. The SchoolID field and the AreaID field are used for filtering results to a particular school or to a particular school district. To create the table schema, follow these steps: <ol> Click Start.</li> Point to Programs, point to Microsoft SQL Server, and then click Query Analyzer.</li> Select in the SQL Server box. Where  is the name of your SQL Server server</li> Type you and you  in the corresponding text boxes, and then click OK.</li> On the Query tab, click Change Database.</li> Select the Northwind database, and then click OK.</li>  Copy the following code to the Query text box: CREATE TABLE [dbo].[Students] (   [StudentID] [int] IDENTITY (1, 1) NOT NULL,    [AreaID] [int] NULL ,    [SchoolID] [int] NULL ,    [TeacherID] [int] NULL ,    [FirstName] [varchar] (20) NOT NULL ,    [MI] [varchar] (5) NULL ,    [LastName] [varchar] (20) NOT NULL ,        [Address] [varchar] (50) NULL ) ON [PRIMARY] GO

ALTER TABLE [dbo].[Students] WITH NOCHECK ADD CONSTRAINT [PK_Students] PRIMARY KEY NONCLUSTERED (       [StudentID]    )  ON [PRIMARY] GO </li> On the Query tab, click Execute.</li></ol>

back to the top

Create stored procedures
<ol>  To create the NextStudentPage stored procedure, copy the following code to the Query text box of Query Analyzer: CREATE PROCEDURE NextStudentPage

@SID INT, @PageSize INT = 1, @AreaID INT = NULL, @SchoolID INT = NULL AS

DECLARE @LName VARCHAR(20) DECLARE @FName VARCHAR(20) DECLARE @MI VARCHAR(5)

/* Locate additional parameter values for the last row of the current page.

You must do this because an ASP.NET Datagrid control only stores key values and does not store additional field values that you need.

IF @SID IS NULL SELECT @LName=, @FName=, @MI='', @SID=0 ELSE SELECT TOP 1 @LName = LastName, @FName = FirstName, @MI = MI  FROM STUDENTS WHERE StudentID = @SID

/* RESTRICT THE NUMBER OF ROWS RETURNED. */

SET ROWCOUNT 25 IF @PageSize=2 SET ROWCOUNT 100 IF @PageSize=3 SET ROWCOUNT 500

/* Select the next page of data. */

SELECT * FROM STUDENTS WHERE ((LastName>@LName)  OR    (LastName=@LName AND FirstName>@FName)   OR    (LastName=@LName AND FirstName=@FName AND MI>@MI)   OR    (LastName=@LName AND FirstName=@FName AND MI=@MI AND StudentID>@SID)) AND  (@AreaID IS NULL  OR AreaID=@AreaID) AND  (@SchoolID IS NULL OR SchoolID=@SchoolID) ORDER BY LastName, FirstName, MI, StudentID

/* TURN OFF THE ROWCOUNT LIMIT. */

SET ROWCOUNT 0 </li> On the Query tab, click Execute.</li>  To create the PrevStudentPage stored procedure, copy the following code to the Query text box of Query Analyzer: CREATE PROCEDURE PrevStudentPage

@SID INT, @PageSize INT = 1, @AreaID INT = NULL, @SchoolID INT = NULL AS

DECLARE @LName VARCHAR(20) DECLARE @FName VARCHAR(20) DECLARE @MI VARCHAR(5)

/* Locate additional parameter values for the first row of the current page.

You must do this because an ASP.NET Datagrid control only stores key values and does not store additional field values that you need.

IF @SID IS NULL /* SELECT A VALUE BEYOND THE LAST RECORD. */  SELECT TOP 1 @LName = LastName, @FName = FirstName, @MI = MI, @SID = StudentID + 1 FROM STUDENTS ORDER BY LastName DESC, FirstName DESC, MI DESC, StudentID DESC ELSE SELECT TOP 1 @LName = LastName, @FName = FirstName, @MI = MI  FROM STUDENTS WHERE StudentID = @SID

/* Restrict the number of rows returned. */

SET ROWCOUNT 25 IF @PageSize=2 SET ROWCOUNT 100 IF @PageSize=3 SET ROWCOUNT 500

/* Select the previous page of data - This returns in descending order. */

SELECT * INTO #TempStudent FROM STUDENTS WHERE ((LastName<@LName)  OR    (LastName=@LName AND FirstName<@FName)   OR    (LastName=@LName AND FirstName=@FName AND MI<@MI)   OR    (LastName=@LName AND FirstName=@FName AND MI=@MI AND StudentID<@SID)) AND  (@AreaID IS NULL  OR AreaID=@AreaID) AND  (@SchoolID IS NULL OR SchoolID=@SchoolID) ORDER BY LastName DESC, FirstName DESC, MI DESC, StudentID DESC

/* Reorder the records in ascending order. */

SELECT * FROM #TempStudent ORDER BY LastName, FirstName, MI, StudentID

/* Clean up the database. */

SET ROWCOUNT 0 DROP TABLE #TempStudent </li> On the Query tab, click Execute.</li></ol>

back to the top

Create an ASP.NET Web application
<ol> Start Microsoft Visual Studio .NET.</li> <li>On the File menu, point to New, and then click Project.</li> <li>Click Visual C# Projects under Project Types, and then click ASP.NET Web Application under Templates.</li> <li>Name the project PagingTest. By default, WebForm1.aspx is created.</li> <li>Right-click WebForm1.aspx, and then click View HTML Source.</li> <li> Replace the existing code with the following code: <%@ Page language=&quot;c#&quot; Codebehind=&quot;WebForm1.aspx.cs&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;PagingTest.WebForm1&quot; %> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; > <HTML> <HEAD> WebForm1 </HEAD> <body MS_POSITIONING=&quot;GridLayout&quot;> <form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;> <asp:button id=&quot;Button1&quot; style=&quot;Z-INDEX: 101; LEFT: 309px; POSITION: absolute; TOP: 233px&quot; runat=&quot;server&quot; Text=&quot;Button&quot;></asp:button> <asp:label id=&quot;Label1&quot; style=&quot;Z-INDEX: 102; LEFT: 310px; POSITION: absolute; TOP: 190px&quot; runat=&quot;server&quot;>Click Button to add Records</asp:label> </HTML> </li> <li>Right-click WebForm1.aspx, and then click View Code.</li> <li> Replace the existing code with the following code: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

namespace PagingTest {   ///     /// Summary description for WebForm1. ///    public class WebForm1 : System.Web.UI.Page {     protected System.Web.UI.WebControls.Button Button1; protected System.Data.SqlClient.SqlConnection sqlConnection1; string [] Fname = new string[5] {&quot;Jhon&quot;,&quot;Martin&quot;,&quot;Rob&quot;,&quot;Leo&quot;,&quot;Amey&quot;}; string [] Lname = new string[5] {&quot;Thompson&quot;,&quot;McMillan&quot;,&quot;Rob&quot;,&quot;King&quot;,&quot;Starr&quot;}; string [] MI   = new string[5] {&quot;M&quot;,&quot;R&quot;,&quot;B&quot;,&quot;K&quot;,&quot;P&quot;}; int AreaIDv; int SchoolIDv; int TeacherIDv; string Addressv; string insertCmd =&quot;&quot;; SqlCommand myCommand; protected System.Web.UI.WebControls.Label Label1; SqlConnection Conn;

private void Page_Load(object sender, System.EventArgs e)       { Label1.Visible=true; //string Fname1=Fname[2]; }

#region Web Form Designer generated code override protected void OnInit(EventArgs e)       { //           // CODEGEN: The ASP.NET Web Form Designer needs this call. //           InitializeComponent; base.OnInit(e); }       ///         /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///        private void InitializeComponent {            this.sqlConnection1 = new System.Data.SqlClient.SqlConnection; this.Button1.Click += new System.EventHandler(this.Button1_Click); //         // sqlConnection1 //         this.sqlConnection1.ConnectionString = &quot;data source= Servername;initial catalog=pubs;&quot; + &quot;persist security info=False;user id=sa;packet size=4096&quot;; this.Load += new System.EventHandler(this.Page_Load);

}       #endregion

private void Button1_Click(object sender, System.EventArgs e)     { Conn = new SqlConnection(&quot;server= Servername;uid=sa;pwd=sa;database=Northwind;&quot;); Conn.Open; for(int i=0;i<1000;i++) {               Random rn = new Random; int j=0; j = rn.Next(1,5); AreaIDv = rn.Next(1,10); TeacherIDv=rn.Next(10,20); SchoolIDv=rn.Next(1,10); Addressv = rn.Next(101, 1999) + &quot; &quot; + &quot; St.&quot;;

insertCmd = &quot;insert into Students (FirstName,LastName,MI,AreaID,SchoolID,TeacherID,Address)&quot;+ &quot;values ('&quot;+Fname[j]+&quot;','&quot;+Lname[j]+&quot;','&quot;+MI[j]+&quot;',&quot;+AreaIDv+&quot;,&quot;+SchoolIDv+&quot;,&quot;+              &quot;&quot;+TeacherIDv+&quot;,'&quot;+Addressv+&quot;')&quot;;

myCommand = new SqlCommand(insertCmd, Conn); myCommand.ExecuteNonQuery; }               Conn.Close; Label1.Text=&quot;Records are Added in Database&quot;; } } } </li> <li>On the Build menu, click Build Solution.</li> <li>In Solution Explorer, right-click PagingTest, point to Add, and then click Add Web Form.</li> <li>Type Paging.aspx in the Name text box, and then click Open.</li> <li>Right-click Paging.aspx, and then click View HTML Source.</li> <li> Replace the existing code with the following code: <%@ Page language=&quot;c#&quot; Codebehind=&quot;Paging.aspx.cs&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;PagingTest.WebForm2&quot; %> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; > <HTML> <HEAD> Paging </HEAD> <body MS_POSITIONING=&quot;GridLayout&quot;> <form id=&quot;WebForm2&quot; method=&quot;post&quot; runat=&quot;server&quot;> <asp:datagrid id=&quot;DataGrid1&quot; style=&quot;Z-INDEX: 100; LEFT: 186px; POSITION: absolute; TOP: 265px&quot; runat=&quot;server&quot;></asp:datagrid> <asp:label id=&quot;Label3&quot; style=&quot;Z-INDEX: 111; LEFT: 5px; POSITION: absolute; TOP: 117px&quot; runat=&quot;server&quot;> Enter 2 - for Page length 100 lines. 3 for Page length 500 lines </asp:label> <asp:label id=&quot;Label2&quot; style=&quot;Z-INDEX: 110; LEFT: 7px; POSITION: absolute; TOP: 91px&quot; runat=&quot;server&quot;> Enter School Code to Filter</asp:label> <asp:textbox id=&quot;txtArea&quot; style=&quot;Z-INDEX: 101; LEFT: 211px; POSITION: absolute; TOP: 38px&quot; runat=&quot;server&quot; Width=&quot;52px&quot;></asp:textbox> <asp:textbox id=&quot;txtSchool&quot; style=&quot;Z-INDEX: 102; LEFT: 210px; POSITION: absolute; TOP: 85px&quot; runat=&quot;server&quot; Width=&quot;52px&quot;></asp:textbox> <asp:textbox id=&quot;txtPageSize&quot; style=&quot;Z-INDEX: 103; LEFT: 209px; POSITION: absolute; TOP: 144px&quot; runat=&quot;server&quot; Width=&quot;54px&quot;></asp:textbox> <asp:label id=&quot;lblEOF&quot; style=&quot;Z-INDEX: 104; LEFT: 344px; POSITION: absolute; TOP: 225px&quot; runat=&quot;server&quot;> No records available for this query</asp:label> <asp:button id=&quot;btnFirst&quot; style=&quot;Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 175px&quot; runat=&quot;server&quot; Text=&quot;ButtonFirst&quot;></asp:button> <asp:button id=&quot;btnNext&quot; style=&quot;Z-INDEX: 106; LEFT: 293px; POSITION: absolute; TOP: 177px&quot; runat=&quot;server&quot; Text=&quot;ButtonNext&quot;></asp:button> <asp:button id=&quot;btnPrev&quot; style=&quot;Z-INDEX: 107; LEFT: 419px; POSITION: absolute; TOP: 176px&quot; runat=&quot;server&quot; Text=&quot;ButtonPrev&quot;></asp:button> <asp:button id=&quot;btnLast&quot; style=&quot;Z-INDEX: 108; LEFT: 551px; POSITION: absolute; TOP: 178px&quot; runat=&quot;server&quot; Text=&quot;ButtonLast&quot;></asp:button> <asp:Label id=&quot;Label1&quot; style=&quot;Z-INDEX: 109; LEFT: 8px; POSITION: absolute; TOP: 35px&quot; runat=&quot;server&quot;>Enter Area Code to Filter</asp:Label> </HTML> </li> <li>Right-click Paging.aspx, and then click View Code.</li> <li> Replace the existing code with the following code: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient;

namespace PagingTest {   ///     /// Summary description for Paging. ///  public class Paging : System.Web.UI.Page {     protected System.Web.UI.WebControls.TextBox txtArea; protected System.Web.UI.WebControls.TextBox txtSchool; protected System.Web.UI.WebControls.TextBox txtPageSize; protected System.Web.UI.WebControls.Label lblEOF; protected System.Web.UI.WebControls.Button btnFirst; protected System.Web.UI.WebControls.Button btnNext; protected System.Web.UI.WebControls.Button btnPrev; protected System.Web.UI.WebControls.Button btnLast; protected System.Web.UI.WebControls.DataGrid DataGrid1;

SqlConnection cnNwind; SqlCommand cmdNext ; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.WebControls.Label Label3; SqlCommand cmdPrev ;

private void Page_Load(object sender, System.EventArgs e)     { // Put user code to initialize the page here if (this.IsPostBack == false) btnFirst_Click(null,null); }

private void btnFirst_Click(object sender, System.EventArgs e)     { cmdNext.Parameters[&quot;@SID&quot;].Value = System.DBNull.Value; cmdNext.Parameters[&quot;@PageSize&quot;].Value = FixNumber(txtPageSize.Text); cmdNext.Parameters[&quot;@AreaID&quot;].Value = FixNumber(txtArea.Text); cmdNext.Parameters[&quot;@SchoolID&quot;].Value = FixNumber(txtSchool.Text); RetrieveData(cmdNext); }

private void btnPrev_Click(object sender, System.EventArgs e)     { if (DataGrid1.DataKeys.Count == 0) cmdPrev.Parameters[&quot;@SID&quot;].Value = System.DBNull.Value; else cmdPrev.Parameters[&quot;@SID&quot;].Value = (int)(DataGrid1.DataKeys[0]); cmdPrev.Parameters[&quot;@PageSize&quot;].Value = FixNumber(txtPageSize.Text); cmdPrev.Parameters[&quot;@AreaID&quot;].Value = FixNumber(txtArea.Text); cmdPrev.Parameters[&quot;@SchoolID&quot;].Value = FixNumber(txtSchool.Text); RetrieveData(cmdPrev); }

private void btnNext_Click(object sender, System.EventArgs e)     { int Count; Count = DataGrid1.DataKeys.Count;

if (Count == 0) cmdNext.Parameters[&quot;@SID&quot;].Value = System.DBNull.Value; else cmdNext.Parameters[&quot;@SID&quot;].Value = (int)(DataGrid1.DataKeys[Count - 1]);

cmdNext.Parameters[&quot;@PageSize&quot;].Value = FixNumber(txtPageSize.Text); cmdNext.Parameters[&quot;@AreaID&quot;].Value = FixNumber(txtArea.Text); cmdNext.Parameters[&quot;@SchoolID&quot;].Value = FixNumber(txtSchool.Text); RetrieveData(cmdNext); }

private void btnLast_Click(object sender, System.EventArgs e)     { cmdPrev.Parameters[&quot;@SID&quot;].Value = System.DBNull.Value; cmdPrev.Parameters[&quot;@PageSize&quot;].Value = FixNumber(txtPageSize.Text); cmdPrev.Parameters[&quot;@AreaID&quot;].Value = FixNumber(txtArea.Text); cmdPrev.Parameters[&quot;@SchoolID&quot;].Value = FixNumber(txtSchool.Text); RetrieveData(cmdPrev); }

private object FixNumber(string inValue) {        int Value; try {           Value = int.Parse(inValue); return Value; }        catch {           return System.DBNull.Value; }     }

private void RetrieveData(SqlCommand cmd) {        SqlDataReader dr; try {           cnNwind.Open; dr = cmd.ExecuteReader; DataGrid1.DataSource=dr; DataGrid1.DataKeyField=&quot;StudentID&quot;; DataGrid1.DataBind; if (DataGrid1.Items.Count>0) {              DataGrid1.Visible=true; lblEOF.Visible=false; }           else {              DataGrid1.Visible=false; lblEOF.Visible=true; }           dr.Close; }        catch(Exception e1) {           Response.Write(e1.ToString); // display error message in a label control // must be made invisible in the try block }        finally {           if (cnNwind.State != ConnectionState.Closed) cnNwind.Close; }     }

#region Web Form Designer generated code override protected void OnInit(EventArgs e)       { //           // CODEGEN: The ASP.NET Web Form Designer needs this call. //           InitializeComponent; base.OnInit(e); }       ///         /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///      private void InitializeComponent {            this.cnNwind = new System.Data.SqlClient.SqlConnection; this.cmdNext = new System.Data.SqlClient.SqlCommand; this.cmdPrev = new System.Data.SqlClient.SqlCommand; //         // cnNwind //         this.cnNwind.ConnectionString = &quot;server=servername ;uid=sa;pwd=sa;database=Northwind;&quot;; //         // cmdNext //         this.cmdNext.CommandText = &quot;[NextStudentPage]&quot;; this.cmdNext.CommandType = System.Data.CommandType.StoredProcedure; this.cmdNext.Connection = this.cnNwind; this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@RETURN_VALUE&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@SID&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@PageSize&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@AreaID&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdNext.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@SchoolID&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); //         // cmdPrev //         this.cmdPrev.CommandText = &quot;[PrevStudentPage]&quot;; this.cmdPrev.CommandType = System.Data.CommandType.StoredProcedure; this.cmdPrev.Connection = this.cnNwind; this.cmdPrev.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@RETURN_VALUE&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdPrev.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@SID&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdPrev.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@PageSize&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdPrev.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@AreaID&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.cmdPrev.Parameters.Add(new System.Data.SqlClient.SqlParameter(&quot;@SchoolID&quot;, System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), &quot;&quot;, System.Data.DataRowVersion.Current, null)); this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click); this.btnNext.Click += new System.EventHandler(this.btnNext_Click); this.btnPrev.Click += new System.EventHandler(this.btnPrev_Click); this.btnLast.Click += new System.EventHandler(this.btnLast_Click); this.Load += new System.EventHandler(this.Page_Load);

}

#endregion } } </li> <li>On the Build menu, click Build Solution.</li></ol>

back to the top

Populate the database
<ol> <li>Locate the WebForm1.aspx Web page by using the following URL:

http://localhost/PagingTest/WebForm1.aspx

</li> <li>Click Button1 to insert 1000 records in the Students table that you created in the Northwind database.</li></ol>

back to the top

Test dynamic paging
Locate the Paging.aspx Web page by using the following URL:

http://localhost/PagingTest/Paging.aspx

Notice that you can dynamically page through the returned records.

back to the top

<div class="references_section">