SoFunction
Updated on 2025-03-09

Summary of three pagination methods

There are usually three methods of paging, namely, the built-in data display space such as GridView and other paging, third-party paging controls such as aspnetpager, stored procedure paging, etc. Here are some summary.
The first one: Use GridView to come with paging, which is the easiest way to paging.
Front desk method:
Copy the codeThe code is as follows:

<asp:GridView ID="GridView1" AllowPaging="true" runat="server"
onpageindexchanging="GridView1_PageIndexChanging" PageSize="3">
</asp:GridView>

Background method:
Code
Copy the codeThe code is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace
{
public partial class Test :
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
DataTable dt=new DataTable();
("ID");
("Name");
for (int i = 0; i < 10;i++ )
{
((), ());
}
this. = dt;
this.();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this. = ;
BindData();
}
}
}

The second type: use personalized display to paginate
Quotes that need to be added here
front desk:
Copy the codeThe code is as follows:

<form runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
CustomInfoHTML="%CurrentPageIndex% page, total %PageCount% page, %PageSize% bar per page"
FirstPageText="Homepage" LastPageText="LastPage" LayoutType="Table" NextPageText="NextPage"
onpagechanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList"
PagingButtonLayoutType="Span" PrevPageText="Previous page" ShowCustomInfoSection="Left"
ShowPageIndexBox="Always" SubmitButtonText="Go" PageSize="4" TextAfterPageIndexBox="Page"
TextBeforePageIndexBox="Go to">
</webdiyer:AspNetPager>
</div>
</form>

Backstage:
Copy the codeThe code is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace
{
public partial class Test :
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
DataTable dt=new DataTable();
("ID");
("Name");
for (int i = 0; i < 10;i++ )
{
((), ());
}
DataSet ds = new DataSet();
(dt);
Pager(this.GridView1, this.AspNetPager1, ds);
}
protected void Pager(GridView dl, anp, dst)
{
PagedDataSource pds = new PagedDataSource();
= [0].DefaultView;
= true;
= [0].;
= - 1;
= ;
= pds;
();
}
protected void AspNetPager1_PageChanging(object src, e)
{
= ;
BindData();
}
}
}

The third type: Use AspNetPager to combine stored procedures for pagination
This method of pagination is a little more complicated, but it can cope with a relatively large amount of data.
front desk:
Copy the codeThe code is as follows:

<asp:GridView ID="GridView1" runat="server" CssClass="GridTable" AutoGenerateColumns="false" onrowdatabound="GridView1_RowDataBound" >
</asp:GridView>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
CustomInfoHTML="%CurrentPageIndex% page, total %PageCount% page, %PageSize% bar per page"
FirstPageText="Homepage" LastPageText="LastPage" LayoutType="Table" NextPageText="NextPage"
onpagechanged="AspNetPager1_PageChanged" PageIndexBoxType="DropDownList"
PagingButtonLayoutType="Span" PrevPageText="Previous page" ShowCustomInfoSection="Left"
ShowPageIndexBox="Always" SubmitButtonText="Go" PageSize="4" TextAfterPageIndexBox="Page"
TextBeforePageIndexBox="Go to">
</webdiyer:AspNetPager>

Backstage:
Copy the codeThe code is as follows:

//The two properties of aspnetpager need to be passed in the binding method
protected void DataBind(){
DataSet ds = (,,( this.),
this.,,,
,);//Note that the last two parameters are the properties of aspnetpager.
this. = ds;
this.();
}
//Page index change event of pagination control
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
BindDetailReportToGv();
}
//The number of data strips that need to be loaded for the first time in page_base
DataSet ds = (, , (this.), this., , );
this. = [0].;
BindDetailReportToGv();


The stored procedure used here is quite complicated because SQL statements cannot be placed in the view, and the results cannot be found directly from the table. This stored procedure is a bit abnormal. If a friend sees it, I hope you can give it a guide.
In fact, the core of stored procedures is:
Copy the codeThe code is as follows:

Create PROCEDURE [dbo].[P_GetPagedOrders2005]
(@startIndex INT,
@endindex INT
)
AS
select * from (SELECT ROW_NUMBER() OVER(ORDER BY IPid DESC) AS rownum,
[IPid],[IPFrom],[IPTo],[IPLocation],[IPCity],[IPToNumber],[IPFromNumber] from IPInfo) as U
WHERE rownum between @startIndex and @endIndex
GO


Code
Copy the codeThe code is as follows:

--The following can be ignored
--I'm using stored procedures:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
create PROCEDURE [dbo].[pro_pager]
(@startIndex INT,
@endindex INT,
@strwhere varchar(200)
)
AS
SELECT tb_On_Tick_Info.On_Tick_ID_Int,tb_On_Tick_Info.On_Tick_SellDatetime_Dtm,tb_On_Tick_Info.On_Tick_TicketsNum_Str, tb_Department_Info.Dept_Name_Str, tb_User_Info.User_Name_Str,
tb_On_Tick_Info.On_Tick_SellNumber_Str, tb_On_Tick_Info.On_Tick_ShouldPay_Dec, tb_On_Tick_Info.On_Tick_Count_Int,
tb_On_Tick_Info.On_Tick_Discount_Dec, tb_On_Tick_Details.On_Tick_Details_StartNo_Int, CHARINDEX(N'a',
tb_On_Tick_Info.On_Tick_Note_Text) AS Expr3, tb_User_Info_1.User_Name_Str AS Expr1, tb_Ticket_Type.TicketType_Name_Dec,
COUNT( tb_On_Tick_Details.On_Tick_Details_ID_Int) AS Expr2 ,tb_Department_Info.Dept_ID_Int
into #temp
FROM tb_User_Info INNER JOIN
tb_On_Tick_Info ON tb_User_Info.User_ID_Int = tb_On_Tick_Info.On_Tick_SellPerson_Int INNER JOIN
tb_Department_Info ON tb_User_Info.User_DepartID_Int = tb_Department_Info.Dept_ID_Int INNER JOIN
tb_User_Info AS tb_User_Info_1 ON tb_On_Tick_Info.On_Tick_PayPerson_Int = tb_User_Info_1.User_ID_Int INNER JOIN
tb_On_Tick_Details ON tb_On_Tick_Info.On_Tick_SellNumber_Str = tb_On_Tick_Details.On_Tick_SellNumber_Str INNER JOIN
tb_Ticket_Type ON tb_On_Tick_Details.On_Tick_Details_TicketsType_Int = tb_Ticket_Type.TicketType_ID_Int
where 1=1 +@strwhere
GROUP BY tb_On_Tick_Info.On_Tick_SellDatetime_Dtm,tb_On_Tick_Info.On_Tick_TicketsNum_Str, tb_Department_Info.Dept_Name_Str, tb_User_Info.User_Name_Str,
tb_On_Tick_Info.On_Tick_SellNumber_Str, tb_On_Tick_Info.On_Tick_ShouldPay_Dec, tb_On_Tick_Info.On_Tick_Count_Int,
tb_On_Tick_Info.On_Tick_Discount_Dec, CHARINDEX(N'a', tb_On_Tick_Info.On_Tick_Note_Text), tb_User_Info_1.User_Name_Str,
tb_Ticket_Type.TicketType_Name_Dec, tb_On_Tick_Details.On_Tick_Details_StartNo_Int ,tb_Department_Info.Dept_ID_Int,tb_On_Tick_Info.On_Tick_ID_Int
declare @sql varchar(8000)
set @sql = 'select CONVERT(varchar(12) , On_Tick_SellDatetime_Dtm, 111 ) as On_Tick_SellDatetime_Dtm,Dept_Name_Str,User_Name_Str,On_Tick_SellNumber_Str,convert(varchar(15), On_Tick_ShouldPay_Dec) as On_Tick_ShouldPay_Dec,On_Tick_Count_Int,On_Tick_Discount_Dec'
select @sql=@sql+',sum(case tickettype_name_dec when '''+tickettype_name_dec+''' then expr2 else 0 end) ['+tickettype_name_dec+']'
from (select distinct tickettype_name_dec from tb_Ticket_Type ) as a
set @sql=@sql+' ,expr3,Expr1,On_Tick_TicketsNum_Str,Dept_ID_Int,On_Tick_ID_Int into ##t from #temp
group by On_Tick_SellDatetime_Dtm,Dept_Name_Str,On_Tick_TicketsNum_Str,User_Name_Str,On_Tick_SellNumber_Str,On_Tick_ShouldPay_Dec,On_Tick_Count_Int,
On_Tick_Discount_Dec ,expr3,Expr1,Dept_ID_Int,On_Tick_ID_Int order by On_Tick_SellDatetime_Dtm '
exec( @sql )
--select * from ##t
select * from (SELECT ROW_NUMBER() OVER(ORDER BY on_tick_id_int DESC) AS rownum,
* from ##t) as U
WHERE rownum between @startIndex and @endIndex
drop table ##t