Asp. NET stored procedures to achieve paging effect (three-tier architecture) _ Practical Tips

Source: Internet
Author: User

The example of this article for everyone to share the asp.net stored process implementation page specific code, for your reference, the specific content as follows

Implementation effect:
Enter the number of pages in the text box, click Go to jump to the page

First join the Bll,dal,dataaccess,model class library under the project
1. Front interface

<%@ page language= "C # autoeventwireup=" true "codebehind=" original refresh paging. Aspx.cs "inherits=" paging. Original Refresh page "%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

2, background code

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Data;
  Namespace page {public partial class original Refresh paging: System.Web.UI.Page {int pagesize = 10; protected void Page_Load (object sender, EventArgs e) {if (!
    IsPostBack) {viewstate["pageindex"] = 1;
    Getlastpageindex ();
   LoadData (); }} private void Getlastpageindex () {BLL. T_news1 bnews = new BLL.
   T_NEWS1 (); int totalcount = Bnews.
   GetRecordCount ("");
   if (totalcount% pagesize = = 0) {viewstate["lastpageindex"] = totalcount/pagesize;
  
  else {viewstate["lastpageindex"] = totalcount/pagesize+1;} private void LoadData () {BLL. T_news1 bnews = new BLL.
   T_NEWS1 (); DataTable dt = bnews.
   Getlistdatatable (Pagesize,convert.toint32 (viewstate["pageindex")); This.
   Gridview1.datasource = DT; This.
   
   Gridview1.databind (); } protected void Btnfirst_click (object SendeR, EventArgs e) {viewstate["pageindex"] = 1;
  LoadData (); } protected void Btnpre_click (object sender, EventArgs e) {int pageindex = Convert.ToInt32 (viewstate["pageindex"])
   ;
    if (pageindex > 1) {pageindex--;
    viewstate["pageindex"] = pageindex;
   LoadData (); } protected void Btnnext_click (object sender, EventArgs e) {int pageindex = Convert.ToInt32 (viewstate[) pagei
   Ndex "]);
    if (PageIndex < Convert.ToInt32 (viewstate["Lastpageindex")) {pageindex++;
    viewstate["pageindex"] = pageindex;
   LoadData (); } protected void Btnlast_click (object sender, EventArgs e) {viewstate["pageindex"] = viewstate["Lastpageindex
   "];
  LoadData ();
   } protected void Linkbutton5_click (object sender, EventArgs e) {int result; if (int.
    TryParse (Txtpageindex.text, out result) = = True) {viewstate["pageindex"] = TxtPageindex.Text.Trim ();
   LoadData ();
  else {txtpageindex.text = "Please enter a valid number";} }
 }
}

 

3. Database stored Procedure

declare @pagesize int;
declare @pageindex int;
SELECT * FROM (select Row_number () "Over" (order by Id) as rownumber,* from t_news1) T
WHERE rownumber> (@pageindex-1) *@ PageSize and rownumber<= @pagesize * @pageindex

go 
CREATE PROC pro_fenye
@pagesize int,
@pageindex int

as
select * FROM (select Row_number () over (order by Id) as rownumber,* from t_news1) T 
WHERE ROWNUMBER&G t; (@pageindex-1) * @pagesize and rownumber<= @pageindex * @pagesize
go
exec pro_fenye 2,5

The above is the entire content of this article, I hope to help you learn.

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.