为DataGrid自定义分页添加自定义导航和分页信息 (转)

访问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;

              }             

         }

     }

}

相关文章:

  • 2022-12-23
  • 2021-05-20
  • 2022-01-08
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2021-10-04
  • 2021-06-17
  • 2022-12-23
  • 2021-09-26
相关资源
相似解决方案