自定义控件,turnPage.ascs.cs
public
int
TotalNum;
//
一共有多少条数据
public int PageSize; // 每页显示多少条数据
public string PageName; // 转发页面的名称
public int TotalPage; // 总共页数
public string PageUrl; // 转发路径
public int PageGroup; //
public void PageS( int pSize, int tNum, string pName, int pGroup)
{
this.PageSize = pSize;
this.TotalNum = tNum;
this.PageName = pName;
this.PageGroup = pGroup;
if ((TotalNum % PageSize) == 0)
{
TotalPage = TotalNum / PageSize;
}
else
{
TotalPage = TotalNum / PageSize + 1;
}
if (PageName.IndexOf("?") > 0)
{
PageUrl = PageName + "&";
}
else
{
PageUrl = PageName + "?";
}
}
public string Installize( int CurPage)
{
int pstart = 0; //起始页
int plast = 0; //终点页
bool pri = false; //上一页
bool next = true; //下一页
int sx = CurPage + 1;
int sxn = CurPage - 1;
string strpri = "<a href=" + PageUrl + "Page=" + sxn.ToString() + "><FONT color=blue>上一页</font></a> ";
string strnext = "<a href=" + PageUrl + "Page=" + sx.ToString() + "><FONT color=blue>下一页</font></a> ";
//确定起始页与终点页
if (CurPage == 1)
{
if (TotalPage <= PageGroup)
{
pstart = 1; plast = TotalPage;
}
else
{
pstart = 1; plast = PageGroup;
}
}
else
{
if (CurPage <= PageGroup + 1)
{
pstart = 1;
}
else
{
pstart = CurPage - PageGroup;
}
if (CurPage <= TotalPage + 1 - PageGroup)
{
plast = CurPage + PageGroup - 1;
}
else
{
plast = TotalPage;
next = false;
}
pri = true;
}
if (pri == false)
{
strpri = "";
}
if (next == false)
{
strnext = "";
}
string g = "";
for (int i = pstart; i <= plast; i++)
{
if (CurPage == i)
{
g += i.ToString() + " ";
}
else
{
g += "<a href=" + PageUrl + "Page=" + i.ToString() + "><FONT color=blue>[" + i.ToString() + "]</font></a> ";
}
}
return strpri + g + strnext;
}
public int PageSize; // 每页显示多少条数据
public string PageName; // 转发页面的名称
public int TotalPage; // 总共页数
public string PageUrl; // 转发路径
public int PageGroup; //
public void PageS( int pSize, int tNum, string pName, int pGroup)
{
this.PageSize = pSize;
this.TotalNum = tNum;
this.PageName = pName;
this.PageGroup = pGroup;
if ((TotalNum % PageSize) == 0)
{
TotalPage = TotalNum / PageSize;
}
else
{
TotalPage = TotalNum / PageSize + 1;
}
if (PageName.IndexOf("?") > 0)
{
PageUrl = PageName + "&";
}
else
{
PageUrl = PageName + "?";
}
}
public string Installize( int CurPage)
{
int pstart = 0; //起始页
int plast = 0; //终点页
bool pri = false; //上一页
bool next = true; //下一页
int sx = CurPage + 1;
int sxn = CurPage - 1;
string strpri = "<a href=" + PageUrl + "Page=" + sxn.ToString() + "><FONT color=blue>上一页</font></a> ";
string strnext = "<a href=" + PageUrl + "Page=" + sx.ToString() + "><FONT color=blue>下一页</font></a> ";
//确定起始页与终点页
if (CurPage == 1)
{
if (TotalPage <= PageGroup)
{
pstart = 1; plast = TotalPage;
}
else
{
pstart = 1; plast = PageGroup;
}
}
else
{
if (CurPage <= PageGroup + 1)
{
pstart = 1;
}
else
{
pstart = CurPage - PageGroup;
}
if (CurPage <= TotalPage + 1 - PageGroup)
{
plast = CurPage + PageGroup - 1;
}
else
{
plast = TotalPage;
next = false;
}
pri = true;
}
if (pri == false)
{
strpri = "";
}
if (next == false)
{
strnext = "";
}
string g = "";
for (int i = pstart; i <= plast; i++)
{
if (CurPage == i)
{
g += i.ToString() + " ";
}
else
{
g += "<a href=" + PageUrl + "Page=" + i.ToString() + "><FONT color=blue>[" + i.ToString() + "]</font></a> ";
}
}
return strpri + g + strnext;
}
显示分页页default.aspx
<%
@ Register Src="turnPage.ascx" TagName="turnPage" TagPrefix="uc1"
%>
uc1:turnPage ID="TurnPage1" runat="server" />
< asp:Label ID ="Label1" runat ="server" Text ="Label" ></ asp:Label >
uc1:turnPage ID="TurnPage1" runat="server" />
< asp:Label ID ="Label1" runat ="server" Text ="Label" ></ asp:Label >
default.aspx.cs
if
(Request.QueryString[
"
Page
"
]
!=
null
)
{
this.TurnPage1.PageS(30, 2000, "default.aspx", 5);
this.Label1.Text = this.TurnPage1.Installize(Int32.Parse(Request.QueryString["Page"]));
}
else
{
this.TurnPage1.PageS(30, 2000, "default.aspx", 5);
this.Label1.Text = this.TurnPage1.Installize(1);
}
{
this.TurnPage1.PageS(30, 2000, "default.aspx", 5);
this.Label1.Text = this.TurnPage1.Installize(Int32.Parse(Request.QueryString["Page"]));
}
else
{
this.TurnPage1.PageS(30, 2000, "default.aspx", 5);
this.Label1.Text = this.TurnPage1.Installize(1);
}