使用AspNetPager高效分页..

第三方控件下载地址:http://www.webdiyer.com/Controls/AspNetPager/Downloads

实现最基本的高效分页 需要两个存储过程,第一个是获取全部数据数量的SQL,第二个是分页用的SQL语句了

 先上SQL代码:分页用的存储过程 

CREATE PROCEDURE Proc_GridView_Pager
    
@startIndex int,
    
@endIndex int
AS
BEGIN
    
select * from (
    
select a.id,a.saleName,a.price,a.count,a.amount,b.Name,a.inDate,row_number()over(order by a.inDate desc)rownum
    
from InBill a
    
inner join InBillType b
    
on a.InTypeId = b.id
) t
where t.rownum >=@startIndex and t.rownum<=@endIndex;
END

 GO 


获取数据总数量的存储过程


 CREATE PROCEDURE Proc_GetAllData_Count

 AS
 

BEGIN

selectcount(*from inbill

 END

GO 

然后给aspnetPager添加PageChanged 事件代码如下:这个是分页用的代码

string commandText = "Proc_GridView_Pager";
            gvInBillList.DataSource 
= SQLHelper.GetDateSet(commandText, CommandType.StoredProcedure,
            new SqlParameter("
@startIndex", anpGridView.StartRecordIndex),
            new SqlParameter("
@endIndex", anpGridView.EndRecordIndex));

            gvInBillList.DataBind(); 

   

最后一步了,就是上面提到的获取全部数据的存储过程,就是在这个时候用了,当页面加载的时候调用方法

 anpGridView.RecordCount = new InBillManager().GetAllDataCount();

原文地址:https://www.cnblogs.com/zhuiyi/p/2049936.html