三层+存储过程实现分页示例代码

时间:2021-05-25

前台设计:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paging.aspx.cs" Inherits="五二一练习.paging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://mand(connection, stroreProcName, parameters);
sqlDA.Fill(dt);
connection.Close();
return dt;
}
}

然后在后台调用即可:
复制代码 代码如下:
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 练习
{
public partial class paging : System.Web.UI.Page
{
int pagesize = 10;
int pageindex = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["pageindex"] = 1;
LadaData();
GetListPageindex();
}
}
private void GetListPageindex()
{
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 LadaData()
{
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;
LadaData();
}
//上一页
protected void btnPre_Click(object sender, EventArgs e)
{
int pageindex = Convert.ToInt32(ViewState["pageindex"]);
if (pagesize>1)
{
pageindex--;
ViewState["pageindex"] = pageindex;
LadaData();
}
}
//下一页
protected void btnNext_Click(object sender, EventArgs e)
{
int pageindex = Convert.ToInt32(ViewState["pageindex"]);
if (pageindex<Convert.ToInt32(ViewState["lastpageindex"]))
{
pageindex++;
ViewState["pageindex"] = pageindex;
LadaData();
}
}
//最后一页
protected void btnLast_Click(object sender, EventArgs e)
{
ViewState["pageindex"] = ViewState["lastpageindex"];
LadaData();
}
//跳转页面
protected void btnSkip_Click(object sender, EventArgs e)
{
int result;
if (int.TryParse(txtPagination.Text, out result) == true)
{
ViewState["pageindex"] = txtPagination.Text.Trim();
LadaData();
}
else
{
txtPagination.Text = "请输入合法的数字";
}
}
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章