Sqlhelper. CS
Public datatable tabpagequery (string SQL, sqlparameter [] paras, commandtype CT)
{
Datatable dt = new datatable ();
Sqlcommand cmd = new sqlcommand ();
Using (sqlconnection conn = new sqlconnection (sqlhelper. Conn ))
{
Conn. open ();
Cmd = new sqlcommand (SQL, Conn );
Cmd. Parameters. addrange (paras );
Cmd. commandtype = CT;
Sqldataadapter da = new sqldataadapter (CMD );
Da. Fill (DT );
Conn. Close ();
}
Return DT;
}
Rpinfo. CS
/* Total Number of retrieved information */
Public int calrecordcount ()
{
Sqlconnection conn = new sqlconnection (sqlhelper. Conn );
Sqlcommand cmd;
Int res;
String plain text = "select count (1) From enterinfo ";
Conn. open ();
Using (cmd = new sqlcommand (plain text, Conn ))
{
Res = int. parse (CMD. executescalar (). tostring ());
}
Conn. Close ();
Return res;
}
Public datatable infopage (INT pagesize, int pageindex)
{
Datatable dt = new datatable ();
String plain text = "pro_infopage ";
Sqlparameter [] Param = {New sqlparameter ("@ pagesize", pagesize ),
New sqlparameter ("@ pageindex", pageindex)
};
Dt = new sqlhelper (). tabpagequery (plain text, Param, commandtype. storedprocedure );
Return DT;
}
Aspx. CS
When a page is loaded: This rpinfo is the repeater name.
Rpinfo. datasource = new rpinfo (). infopage (anpinfo. pagesize, anpinfo. currentpageindex );
Rpinfo. databind ();
Aspnetpager:
Protected void anpinfo_pagechanged (Object sender, eventargs E)
{
Anpinfo. recordcount = RP. calrecordcount ();
Rpinfo. datasource = new rpinfo (). infopage (anpinfo. pagesize, anpinfo. currentpageindex );
Rpinfo. databind ();
}
Stored Procedure:
Create proc pro_infopage
@ Pageindex int,
@ Pagesize int
As
Declare @ SQL varchar (8000)
Set @ SQL =
'Select top '+ ltrim (@ pagesize) +' * From enterinfo where id not in (select top '+ ltrim (@ pageindex-1) * @ pagesize) + 'id from enterinfo)'
Exec (@ SQL)
Go