Sqlhelper + aspnetpager + repeater stored procedure page

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.