關於翻頁一直很讓我撓頭,今天總結乙個比較經典的。
1.pagecontrol.ascx
<%@ control language="c#" autoeventwireup="true" codebehind="pagecontrol.ascx.cs" inherits="usercontol.pagecontrol" %>
(共條記錄)
...
2.pagecontrol.ascx.cs檔案
using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.web.services.description;
using system.collections.generic;
namespace usercontol
catch
}set
}public int totalrecordcount
catch
}set
}public int recordperpage
catch
}set
}public int totalpage
}//"******"/"full"
private string style;
public string buttonstyle
set}
public delegate void pagechangehandler(int page);
public event pagechangehandler pagechanged;
public void paint()
else
}protected void page_load(object sender, eventargs e)
if (currentpage > totalpage)
}else
catch
if (currentpage < 0)
if (currentpage > totalpage)
if (this.ispostback)
if (this.next5.uniqueid.equals(request["__eventtarget"]))
foreach (string param in request.params.keys)
if (param.equals(this.prev2.uniqueid))
if (param.startswith(this.pagebuttons.uniqueid))
if (param.equals(this.next.uniqueid))
if (param.equals(this.next2.uniqueid))
if (param.equals(this.go.uniqueid))}}
else
}void datalist1_itemdatabound(object sender, repeateritemeventargs e)
else
}private void makepagelist(int ilinecount, int itotal, int icurrentpage, listpagebuttons)
int end = totalpage - icurrentpage;
if (end > width)
while (start + end > width)
else if (totalpage - icurrentpage <= width && end > middle)
else
else}}
if (totalpage - icurrentpage <= middle)
if ((icurrentpage >= 0 && icurrentpage <= totalpage - 1))
if (icurrentpage - start - 1 >= 0)
for (int i = icurrentpage - start; i <= icurrentpage + end; i++)
}if (icurrentpage + end + 2 <= totalpage)
if (icurrentpage + 1 <= totalpage - 1)}}
private string getchangepagejs(int page)
private string getchangepagejs(string page)
class buttonpack
}3.呼叫的地方:test.aspx
先註冊,再呼叫:
<%@ register src="~/pagecontrol.ascx" tagprefix="page" tagname="pagercontrol" %>
4.test.aspx.cs
// 翻頁初始化
this.page1.currentpage = 0;
this.page1.totalrecordcount = 0;
this.page1.recordperpage = 10;
this.page1.paint();
usermanagement usermanagement = new usermanagement ();
list = usermanagement .getinfobyuserid(
this.page1.recordperpage,
this.page1.currentpage,
ref total,
(string)viewstate["status"],
userid);
this.page1.totalrecordcount = total;
this.page1.paint();
5.後台的儲存過程:sp_getuserinfo
create proc [dbo].[sp1_online_getorderinfo](
@pagesize int,
@currpage int,
@total int output,
@status nvarchar(1),
@userid int)as
set lock_timeout 1000
declare @retcode int
select @total = count(1)
from table1 as o with(nolock)
where
(@status is null or o.status = @status )
and o.userid = @userid
select
a,b,
c,rowno
from
(select
o.a,
i.b,
d.c,
row_number()over(
order by o.id desc
) as rowno
from table1 as o with(nolock)
inner join table2 as i with(nolock) on i.id= o.id
inner join table3 as d with(nolock) on d.id= o.id
where
(@status is null or o.status = @status)
and o.userid = @userid
) t1
where t1.rowno - 1 >= (@currpage*@pagesize)
and t1.rowno - 1 < ((@currpage+1)*@pagesize)
order by t1.rowno
6.呼叫儲存過程的檔案(資料層)userdb.cs
internal listgetinfobyuserid(
int pagesize,
int currpage,
ref int total,
string status,
int userid)
internal static listgetlistfromdataset(dataset dataset)
return retlist;
}else
}7.業務層畫面
public listgetinfobyuserid(
int pagesize,
int currpage,
ref int total,
string status,
int userid)
{userdb userdb = new userdb();
return userdb.getinfobyuserid(pagesize, currpage, ref total, status, userid);
Android自定義控制項之自定義組合控制項(三)
前兩篇介紹了自定義控制項的基礎原理android自定義控制項之基本原理 一 自定義屬性android自定義控制項之自定義屬性 二 今天重點介紹一下如何通過自定義組合控制項來提高布局的復用,降低開發成本,以及維護成本。1.第一種方式 直接在每個xml布局中寫相同的標題欄布局 這種方式沒有任何布局復用的...
Android自定義控制項之自定義組合控制項
前兩篇介紹了自定義控制項的基礎原理android自定義控制項之基本原理 一 自定義屬性android自定義控制項之自定義屬性 二 今天重點介紹一下如何通過自定義組合控制項來提高布局的復用,降低開發成本,以及維護成本。1.第一種方式 直接在每個xml布局中寫相同的標題欄布局 這種方式沒有任何布局復用的...
自定義控制項 容器控制項
今天想做個自定義容器控制項,但是在網上找了半天都沒有找到,可以在對應的panel裡進行拖拽控制項的,多以今天寫一下關於怎麼做乙個自定義容器控制項 自定義容器控制項需要在自定義控制項中加入 1 browsable false designerserializationvisibility design...