宝哥软件园

ASP .网存储过程实现分页效果(三层架构)

编辑:宝哥软件园 来源:互联网 时间:2021-10-31

本文实例为大家分享了ASP .网存储过程实现分页的具体代码,供大家参考,具体内容如下

实现效果:文本框内输入跳转的页数,点击去会跳转到该页

首先在项目下加入BLL,DAL,数据访问,模型类库1、前台界面

"%@"页面语言="c#"AutoEventWireup="true "代码隐藏=""原始刷新分页。aspx。cs"Inherits="分页。原始刷新分页' %!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN ' ' http://www .w3。L1-过渡时期。DTD ' html xmlns=' http://www .w3。org/1999/XHTML ' head runat=' server ' title/title script src=' http : js/jquery 1。7 .js ' type=' text/JavaScript '/script focus(function(){ $(this)).val(" ");})})))/脚本/头体表单ID=' form 1 ' runat=' server ' div asp3360 GridView ID=' GridView 1 ' runat=' server ' AutoGenerateColumns=' False ' Columns asp: bound field数据字段=' ID ' head ertext='编号/asp: boundfield数据字段=' news title '标题文本='新闻标题/asp: boundfield数据字段=“新闻内容”标题文本=”新闻内容/asp3360 boundfield数据字段=' create time '数据格式字符串=' { 0: yyyy-MM-DD hh :MM 3360s } 标题文本='创建时间//Columns/ASP : GridView/div/div ASP :链接按钮ID=' BTN优先' runat='服务器' onclick=' BTN优先_ Click '第一页/asp3360链接按钮asp:链接按钮ID=' btnPre ' runat=' server ' onclick=' btnPre _ Click '上一页/asp3360链接按钮asp:链接按钮ID=' btnNext ' runat=' server ' onclick=' btnNext _ Click '下一页/asp3360链接按钮asp:链接按钮ID=' BTN 上次运行时间='服务器'单击时间=' BTN上次单击时间'最后一页/asp3360 link buttonasp : textbox ID=' txtPageindex ' runat=' server '/ASP : textbox ASP : link button ID=' link button 5 ' runat=' server ' onclick=' link button 5 _ Click ' go/ASP 3360 link button/div/form/body/html 2、后台代码

使用系统;使用系统。集合。通用;使用系统Linq .使用系统网络.使用系统网络。用户界面使用系统。网络控件;使用系统。数据;命名空间分页{公共分部类原始刷新分页:系统网络。UI。页面{ int pagesize=10受保护的无效页面_加载(对象发送方,事件参数e) { if(!IsPostBack){ ViewState[' page index ']=1;GetLastPageindex();load DATa();} } private void GetLastPageindex(){ BLL .T_News1 bnews=新BLL .t _ news 1();int totalcount=bnews .GetRecordCount(" ");if(总计数% page size==0){ ViewState[' lastpageindex ']=总计数/页面大小;} else { ViewState[' lastpageindex ']=总计数/页面大小1;} }私人void LoadData() { BLL .T_News1 bnews=新BLL .t _ news 1();数据表dt=bnews .GetListDataTable(页面大小,转换. ToInt32(视图状态[' page index ']);这个. GridView1。数据源=dt这个GridView 1 .DataBind();}受保护的void btnFirst_Click(对象发送者,EventArgs e){ ViewState[' page index ']=1;load DATa();}受保护的void btnPre_Click(对象发送者,事件参数e){页间索引=转换.ToInt32(视图状态[' page index ']);if(页面索引1){页面索引-;ViewState['页面索引']=页面索引;load DATa();} }受保护的void btnNext_Click(对象发送者,事件参数e){页间索引=转换.ToInt32(视图状态[' page index ']);if(页面索引转换.ToInt32(视图状态[' lastpageindex ']){ page index;ViewState['页面索引']=页面索引;load DATa();} }受保护的void btnLast_Click(对象发送者,event args e){ ViewState[' page index ']=ViewState[' lastpageindex '];load DATa();}受保护的作废链接按钮5 _点击(对象发送方,事件参数e){ int result;if (int .特里帕斯(txtPageindex .文本,输出结果)=真){视图状态['页面索引']=TxtPageIndex .文字。trim();load DATa();} else { txtPageindex .文本='请输入合法的数字;} } }}3、数据库存储过程

声明@ pagesize int声明@ pageindex intSELECT * FROM(选择ROW_NUMBER()结束于(按身份排序)作为rownumber,* FROM T _ news 1)TWHERE rownumber(@页面索引-1)* @页面大小和ROW NUMBER[email protected]* @ page index go CREATE PROC _ fenye @ page size int,@ pageindex intasselect * from(选择ROW_NUMBER()结束于(按身份排序)作为行号,*从T _ news 1)T其中行号(@页面索引-1)* @页面大小和行号[电子邮件保护]* @页面大小以上就是本文的全部内容,希望对大家的学习有所帮助。

更多资讯
游戏推荐
更多+