




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、三层+存储过程实现分页示例代码_ 前台设计: 代码如下: % Page Language=C# AutoEventWireup=true CodeBehind=paging.aspx.cs Inherits=五二一练习.paging % !DOCTYPE html PUBLIC -/W3C/DTD XHTML 1.0 Transitional/EN l1/DTD/xhtml1-transitional.dtd html xmlns=l head runat=server title/title script src=js/Jquery1.7.js type=text/javascript/sc
2、ript script type=text/javascript $(function () $(#txtPagination).focus(function () $(this).val(); ) ) /script /head body form id=form1 runat=server div asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False Height=336px Width=685px Columns asp:BoundField DataField=Id HeaderText=编号 / asp:Bo
3、undField DataField=NewsTitle HeaderText=标题 / asp:BoundField DataField=NewsContent HeaderText=内容 / asp:BoundField DataField=CreateTime DataFormatString=0:yyyy-MM-dd hh:mm:ss HeaderText=发布时间 / /Columns /asp:GridView asp:LinkButton ID=btnFirst runat=server onclick=btnFirst_Click第一页/asp:LinkButton asp:L
4、inkButton ID=btnPre runat=server onclick=btnPre_Click上一页/asp:LinkButton asp:LinkButton ID=btnNext runat=server onclick=btnNext_Click下一页/asp:LinkButton asp:LinkButton ID=btnLast runat=server onclick=btnLast_Click最终一页/asp:LinkButtonasp:TextBox ID=txtPagination runat=server/asp:TextBox asp:LinkButton I
5、D=btnSkip runat=server onclick=btnSkip_ClickGO/asp:LinkButton /div /form /body /html 首先在数据库创建存储过程 代码如下: create proc usp_role_GetDateByPageIndex pageSize int, pageIndex int as begin select * from ( select *,ROW_NUMBER() over(order by role_id) as rownumber from role) as tbl where tbl.rownumber between
6、 (pageSize*(pageIndex-1)+1) and pageIndex*pageSize end exec usp_role_GetDateByPageIndex 5,3 在项目中添加BLL,DAL,DataAccess,MODEL层 在DAL中写一个方法: 代码如下: /自己写的方法,分页猎取数据列表 public DataTable GetListDataTable(int PageSize, int PageIndex) SqlParameter parameters = new SqlParameter(PageSize, SqlDbType.Int), new SqlPa
7、rameter(PageIndex, SqlDbType.Int) ; parameters0.Value = PageSize; parameters1.Value = PageIndex; return DbHelperSQL.RunProcedureDataTable(usp_role_GetDateByPageIndex, parameters); 在BLL中调用GetListDataTable: public DataTable GetListDataTable(int pagesize, int pageindex) return dal.GetListDataTable(page
8、size, pageindex); 在DbHelper中添加RunProcedureDataTable方法: public static DataTable RunProcedureDataTable(string stroreProcName, IDataParameter parameters) using (SqlConnection connection = new SqlConnection(connectionString) DataTable dt = new DataTable(); connection.Open(); SqlDataAdapter sqlDA = new S
9、qlDataAdapter(); sqlDA.SelectCommand = BuildQueryCommand(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;
10、 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) ViewStatepageindex = 1; LadaData(); GetListPageindex(); private void GetListPageindex() BLL.T_News1 bnews = ne
11、w BLL.T_News1(); int totalcount = bnews.GetRecordCount(); if (totalcount % pagesize = 0) ViewStatelastpageindex = totalcount / pagesize; else ViewStatelastpageindex = totalcount / pagesize + 1; private void LadaData() BLL.T_News1 bnews = new BLL.T_News1(); DataTable dt = bnews.GetListDataTable(pages
12、ize, Convert.ToInt32(ViewStatepageindex); this.GridView1.DataSource = dt; this.GridView1.DataBind(); /第一页 protected void btnFirst_Click(object sender, EventArgs e) ViewStatepageindex = 1; LadaData(); /上一页 protected void btnPre_Click(object sender, EventArgs e) int pageindex = Convert.ToInt32(ViewSta
13、tepageindex); if (pagesize1) pageindex-; ViewStatepageindex = pageindex; LadaData(); /下一页 protected void btnNext_Click(object sender, EventArgs e) int pageindex = Convert.ToInt32(ViewStatepageindex); if (pageindexConvert.ToInt32(ViewStatelastpageindex) pageindex+; ViewStatepageindex = pageindex; LadaData(); /最终一页 protected void btnLast_Click(object sender, EventArgs e) ViewStatepageindex = ViewStatelastpageindex; LadaData(); /跳转页面 protected void btnSkip_C
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 邯郸消防水泵合同范本
- 线上租房售房合同范本
- 道路渣土清运合同范本
- 自助售卖租售合同范本
- 自卸吊车租赁合同范本
- 矿山生产承包合同范本
- 自卸车车租赁合同范本
- 装修材料附加合同范本
- 进口铜矿交易合同范本
- 签了协议能不能签合同
- 华北理工大学2016年《互换性及技术测量》期末考试复习题
- 医院普通外科病史采集、查体及病历书写要点精讲课件
- 食品执行标准对照新版表
- 大班科学《神奇的洞洞》课件
- 第二次全国陆生野生动物资源调查技术规程
- 控制计划CP模板
- 最新苏教牛津译林版英语五年级上册Unit 4《Hobbies》Grammar time 公开课课件
- 路面压浆施工方案
- 第8课时 主题阅读《雨的四季》-2022-2023学年七年级语文上册(部编版)
- Linux基础入门培训
- 现场技术服务报告模版
评论
0/150
提交评论