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