访问Northwind库,为了独立开来这里还是把存储过程列了一下,
CREATE PROCEDURE [GetCustomersDataPage]
@PageIndex INT,
@PageSize INT,
@RecordCount INT OUT,
@PageCount INT OUT
AS
SELECT @RecordCount = COUNT(*) FROM Customers
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
DECLARE @SQLSTR NVARCHAR(1000)
IF @PageIndex = 0 OR @PageCount <= 1
SET @SQLSTR =N'SELECT TOP '+STR( @PageSize )+
' CustomerID, CompanyName,Address,Phone FROM Customers ORDER BY CustomerID DESC
ELSE IF @PageIndex = @PageCount - 1
SET @SQLSTR =N' SELECT * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+
' CustomerID, CompanyName,Address,Phone FROM Customers ORDER BY CustomerID ASC ) TempTable ORDER BY CustomerID DESC'
ELSE
SET @SQLSTR =N' SELECT TOP '+STR( @PageSize )+' * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+
' CustomerID, CompanyName,Address,Phone FROM Customers ORDER BY CustomerID ASC ) TempTable ORDER BY CustomerID DESC'
EXEC (@SQLSTR)
GO
下面就就把代码贴了一下,
Aspx文件代码如下:
<%@ Page language="c#" Codebehind="DataGridCustomPaging.aspx.cs" AutoEventWireup="false" Inherits="ZZ.AspnetPaging.DataGridCustomPaging" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DataGridPaging</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form ;
}
else
{
this.LtlPageCount.Text = PageCount.ToString();
this.LtlPageIndex.Text = (PageIndex + 1).ToString();
}
}
public int PageCount
{
get
{
return this.DataGrid1.PageCount;
}
}
public int PageSize
{
get
{
return this.DataGrid1.PageSize;
}
}
public int PageIndex
{
get
{
return this.DataGrid1.CurrentPageIndex;
}
set
{
this.DataGrid1.CurrentPageIndex = value;
}
}
public int RecordCount
{
get
{
return recordCount;
}
}
}
}