三層+存儲過程實(shí)現(xiàn)分頁示例代碼__第1頁
三層+存儲過程實(shí)現(xiàn)分頁示例代碼__第2頁
三層+存儲過程實(shí)現(xiàn)分頁示例代碼__第3頁
三層+存儲過程實(shí)現(xiàn)分頁示例代碼__第4頁
三層+存儲過程實(shí)現(xiàn)分頁示例代碼__第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、三層+存儲過程實(shí)現(xiàn)分頁示例代碼_ 前臺設(shè)計: 代碼如下: % Page Language=C# AutoEventWireup=true CodeBehind=paging.aspx.cs Inherits=五二一練習(xí).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=標(biāo)題 / asp:BoundField DataField=NewsContent HeaderText=內(nèi)容 / asp:BoundField DataField=CreateTime DataFormatString=0:yyyy-MM-dd hh:mm:ss HeaderText=發(fā)布時間 / /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 首先在數(shù)據(jù)庫創(chuàng)建存儲過程 代碼如下: 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 在項(xiàng)目中添加BLL,DAL,DataAccess,MODEL層 在DAL中寫一個方法: 代碼如下: /自己寫的方法,分頁獵取數(shù)據(jù)列表 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中調(diào)用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; 然后在后臺調(diào)用即可: 代碼如下: 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 練習(xí) 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(); /跳轉(zhuǎn)頁面 protected void btnSkip_C

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。