28,409
社区成员




//===================定义的全局变量==================
//totalrecord从数据库中读出有多少条记录========这个参数要注意修改过
//totalpage通过totalrecord和pagesize算出来,总页数
//currentpage是当前页
//pagesize是每页显示的记录数,就是3*8了。
//numbercount是显示的数字页码个数,默认显示10个页码
int totalrecord=0,totalpage = 0, currentpage = 0, pagesize = 24, numbercount = 10;
//=====================================
//获取导航的方法
public string GetGuideStr()
{
string Str = "";
int Index, Temp;
Temp = (currentpage / numbercount) * numbercount;//算出数字页码的开始数字
Index = Temp;
if (Index == 0)//有可能得0,而数字页码又不从0开始,所以更改为1
Index = 1;
while (Index <= totalpage)//循环输出数字页码
{
if (Index == currentpage)
Str += "<font color='red'>" + Index + "</font>";//把页码变红,指明为当前页
else
Str += "<a href='?page=" + Index + "'>" + Index + "</a>";
Index++;//输出下一个
if (Index > (Temp + numbercount)) break;//如果输出的页码个数大于定义显示的个数时退出循环
}
return Str;//返回连接好的页码字符串
}
CREATE proc readProduct
@PageSize int=24,--默认24条
@PageIndex int=1--默认第一页
as
declare@strSQL nvarchar(1000)
if @PageIndex=1
set @strSQL='select top '+str(@PageSize)+' * from 商品表 order by pid desc'
else
set @strSQL='select top '+str(@PageSize)+' * from 商品表 '
+' where pid<(select min(pid) from '
+'(select top '+str((@PageIndex-1)*@PageSize)+' pid from 商品表 order by pid desc ) as t) order by pid desc'
exec(@strSQL)
GO