简体   繁体   English

网格视图中的自定义分页

[英]Custom Paging in a Grid View

I have a grid view in web user control and I'm dynamically adding the web user control inside an aspx page. 我在Web用户控件中有一个网格视图,并且正在将Web用户控件动态添加到aspx页面中。 I want custom pagination inside the grid so that initially it only loads the first 10 records so that the user control loads quickly, and then by clicking on "next" or page numbers it will load the next group of 10 records. 我希望在网格内进行自定义分页,以便最初仅加载前10条记录,以便用户控件快速加载,然后单击“下一页”或页码将加载下一组10条记录。 How can this be achieved? 如何做到这一点?

If You use Sqlserver's Stored Procedure then pass Two parameters which is Page Size and Page No. 如果您使用Sqlserver的存储过程,则传递两个参数,即“页面大小”和“页面号”。

In Page size it contains total number of record display and Page no contains Current Page. 在“页面大小”中,它包含记录显示的总数,“页面号”中包含“当前页面”。

In short you have to fetch only Page size record not all and call that stored procedure in grid's Page index changed Event. 简而言之,您只需要获取页面大小记录而不是全部记录,并在网格的页面索引更改事件中调用该存储过程。

this is a sample query to show how to fetch n records from query according to pagenumber 这是一个示例查询,显示了如何根据页码从查询中获取n条记录

 create PROCEDURE [ProductCategorySearch]
    @PageIndex int = 1,
    @PageSize int = 10
    AS
    BEGIN

    DECLARE @StartRow int
    DECLARE @EndRow int

    SET @StartRow = (@PageSize * (@PageIndex - 1))  + 1  
    SET @EndRow = @PageSize * @PageIndex + 1

    SET NOCOUNT ON;

    WITH ArticleSearch AS
    (
        SELECT
           ROW_NUMBER() OVER 
             (
                -- Dynamic sorting
                ORDER BY 
                      a.pCategory_ID  ASC                

              ) AS RowNumber, 
                a.pCategory_ID ,a.pCategory_Name from     tblProductCategory a  

    )
    -- Statement that executes the CTE
    SELECT a.*,(select COUNT(*) from ArticleSearch) as RCount 
    FROM
          ArticleSearch a
    WHERE
          a.RowNumber BETWEEN @StartRow AND @EndRow - 1
    ORDER BY
          a.RowNumber

    END

您可以为此使用GridView.PageSize属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM