Pagination of C # encapsulated stored procedures

Source: Internet
Author: User

DAL layer:

Public DataTable getdatabypage (int pageindex,int pagesize,out int totalcount)

{

totalcount=0;

1.0 define the name of the stored procedure, which must be the stored procedure that exists in the database

String Prodname= "Usp_getlistbypage";

2.0 defining an array of parameters required for a stored procedure

Sqlparameter[] Params=new sqlparameter[]{

New SqlParameter ("@pageIndex", PageIndex),

New SqlParameter ("@pageSize", PageSize),

New SqlParameter ("@totalcount", TotalCount)

};

3.0 because the TotalCount parameter type in the stored procedure is output, you should add a description to it here

PARAMS[2]. Direction=parameterdirection.output;

4.0 start execution, note that execution must be in get params[2]. Value before it is run, otherwise the number of rows that do not get a true qualifying data totalcount

DataSet dt=dbhelpersql.runprocedure (prodname,params, "list");

if (params[2]. Value!=null)

{

Totalcount=int. Parse (Params[2]. Value.tostring ());

}

Return DS. Tables[0];

}

BLL Layer:

Public list< Table Entities > getlistbypage (int pageindex,int pagesize,out int totalcount)

{

DataTable Dt=dal. Getlistbypage (Pageindex,pagesize,out totalcount);

return datatabletolist (DT);

}

Site Layer:

public void Getlistbypage ()

{

1.0 accept AJAX requests or URL requests passed over parameters

String pageindex=request.querystring["PageIndex"];

String pagesize=request.querystrinig["PageSize"];

2.0 validation of parameter legitimacy to determine if int

..........

3.0 Convert pageindex and pagesize to int as parameter pass

int Ipageindex=int. Parse (PageIndex);

int Ipagesize=int. Parse (pageSize);

int totalcount=0;

4.0 paging method calling the BLL layer

list< Table entities > list = BLL. Getdatalistbypage (Ipageindex,ipagesize,out totalcount);

--Here's a question, I'm sure to go back to the list to the front end, but also to return the total number of totalcount, or return totalcount/pagesize=, which I would probably, this is about to start

--Study our pagination control.

Example: Jpageinate pagination control

Use of pagination control, see the next article

}

Pagination of C # encapsulated stored procedures

Related Article

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.