using System;
using System
using System
namespace Zhuwenfeng
{
public class MyPager
{
/// <summary>
/// 總數據條數
/// </summary>
public int TotalCount { get; set; }
/// <summary>
/// 每頁數據條數
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// 當前頁碼(從
/// </summary>
public int CurrentPageIndex { get; set; }
/// <summary>
/// 顯示出來最多的頁碼數量
/// </summary>
public int MaxPagerCount { get; set; }
/// <summary>
/// 頁碼鏈接的地址格式
/// </summary>
public string UrlFormat { get; set; }
public MyPager()
{
PageSize =
MaxPagerCount =
}
/// <summary>
/// 嘗試從字符串pn中解析當前頁面賦值給CurrentPageIndex
/// </summary>
/// <param name=
public void TryParseCurrentPageIndex(string pn)
{
int temp;
if (int
{
CurrentPageIndex = temp;
}
else
{
CurrentPageIndex =
}
}
/// <summary>
/// 創建頁碼鏈接
/// </summary>
/// <param name=
/// <param name=
/// <returns></returns>
private string GetPageLink(int i
{
StringBuilder sb = new StringBuilder()
string url = UrlFormat
sb
return sb
}
/// <summary>
/// 檢查輸入參數
/// </summary>
private void Check()
{
Debug
Debug
Debug
}
/// <summary>
///渲染到前台到得HTML代碼
/// </summary>
/// <returns></returns>
public string Render()
{
Check()
StringBuilder sb = new StringBuilder()
double tempCount = TotalCount / PageSize;
int pageCount = (int)Math
//計算顯示的頁碼數(當總頁碼大於MaxPagerCount)的起始頁碼
int visibleStart = CurrentPageIndex
if (visibleStart <
{
visibleStart =
}
//計算顯示的頁碼數(當總頁碼大於MaxPagerCount)的起始頁碼
int visibleEnd = visibleStart + MaxPagerCount;
//顯示最多MaxPagerCount條
//如果算出來的結束頁碼大於總頁碼的話則調整為最大頁碼
if (visibleEnd >pageCount)
{
visibleEnd = pageCount;
}
if (CurrentPageIndex >
{
sb
sb
}
else
{
sb
//如果沒有上一頁了
sb
}
//繪制可視的頁碼鏈接
for (int i = visibleStart; i <= visibleEnd; i++)
{
//當前頁不是超鏈接
if (i == CurrentPageIndex)
{
sb
}
else
{
sb
}
}
if (CurrentPageIndex < pageCount)
{
sb
sb
}
else
{
sb
sb
}
return sb
}
}
}
二
public partial class 分頁測試 : System
{
protected string PagerHTML { get; private set; }
protected void Page_Load(object sender
{
var pager = new MyPager()
pager
pager
pager
int startRowIndex = (pager
so_KeywordLogBLL bll = new so_KeywordLogBLL()
pager
Repeater
Repeater
PagerHTML = pager
}
}
三
<form id=
<div>
<asp:Repeater ID=
<ItemTemplate>
<li>
<%#Eval(
</li>
</ItemTemplate>
</asp:Repeater>
<div class=
<%=PagerHTML%>
</div>
</div>
</form>
四
<style type=
{
text
padding
padding
padding
float: right;
padding
}
{
border
text
border
padding
line
margin:
outline
padding
padding
background: #fff;
color: #
font
border
border
text
padding
}
{
border
border
color: #f
border
border
text
}
{
}
{
border
text
padding
line
border
margin:
padding
padding
border
background: #f
color: #fff;
font
border
padding
}
</style>
五
public int GetTotalCount()
{
string sql =
return (int)DbHelperSQL
}
public DataSet GetPagedData(int minrownum
{
string sql =
SqlParameter[] parameters = { new SqlParameter(
parameters[
parameters[
return DbHelperSQL
}
六
create PROCEDURE GetPageDataOutRowPageCount
(
@PageIndex int =
@PageSize int =
@RowCount int output
@PageCount int output
)
AS
begin
DECLARE @sql NVARCHAR(
select @RowCount =COUNT(SID)
SET @sql=
EXEC(@sql)
end
select top
select * from (select *
where t
第n頁
From:http://tw.wingwit.com/Article/program/net/201311/13748.html