asp怎么分页显示啊?
我刚学asp不知道怎么分页显示数据和翻页请高手做下详细解答越详细越好谢谢我的代码:<%dimstrSql,rs,i,PageNosql="selecttop100*fro...
我刚学asp不知道怎么分页显示数据和翻页请高手做下详细解答 越详细越好 谢谢
我的代码:
<%
dim strSql,rs,i,PageNo
sql="select top 100 * from shuju "
set rs=Server.CreateObject("ADODB.RecordSet")
rs.open Sql,conn,3,3
if rs.eof then
outerr("没有这条信息!")
response.end
end if
rs.update
strSql="select * from [shuju] where yname='" & session("yname") & "'order by id desc"
%>
<center>
<center><font color="#0033FF"size=+6>游戏用户信息</font></center>
<%do while not rs.eof%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>管理页面</title>
</head>
<body bgcolor="#99FFCC">
<table width="900" border="0" cellspacing="1" cellpadding="0" bgcolor="#FFCC99" frame=box>
<tr>
<td width="200" bgcolor="#fff9e2" height="30" align="center" valign="middle" class="font"><font color="#FF6600">用户名</font></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#fff9e2"><font color="#FF6600">密码</font></td>
<td width="200" bgcolor="#fff9e2" height="30" align="center" valign="middle" class="font"><font color="#FF6600">大区</font></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#fff9e2"> <font color="#FF6600">等级</font></td>
<td width="200" bgcolor="#fff9e2" height="30" align="center" valign="middle" class="font"><font color="#FF6600">仓库密码</font></td>
</tr>
<tr>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("yname")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("ymima")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("daqu")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("dengji")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("cmima")%></td>
</tr>
</table>
<%
rs.movenext
loop%>
<table width="900" border="0" cellspacing="1" cellpadding="0" bgcolor="#fff9e2" frame=box>
<tr>
<td width="900" height="50 align="reft" valign="middle" class="font">
</td>
</tr>
</table> 展开
我的代码:
<%
dim strSql,rs,i,PageNo
sql="select top 100 * from shuju "
set rs=Server.CreateObject("ADODB.RecordSet")
rs.open Sql,conn,3,3
if rs.eof then
outerr("没有这条信息!")
response.end
end if
rs.update
strSql="select * from [shuju] where yname='" & session("yname") & "'order by id desc"
%>
<center>
<center><font color="#0033FF"size=+6>游戏用户信息</font></center>
<%do while not rs.eof%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>管理页面</title>
</head>
<body bgcolor="#99FFCC">
<table width="900" border="0" cellspacing="1" cellpadding="0" bgcolor="#FFCC99" frame=box>
<tr>
<td width="200" bgcolor="#fff9e2" height="30" align="center" valign="middle" class="font"><font color="#FF6600">用户名</font></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#fff9e2"><font color="#FF6600">密码</font></td>
<td width="200" bgcolor="#fff9e2" height="30" align="center" valign="middle" class="font"><font color="#FF6600">大区</font></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#fff9e2"> <font color="#FF6600">等级</font></td>
<td width="200" bgcolor="#fff9e2" height="30" align="center" valign="middle" class="font"><font color="#FF6600">仓库密码</font></td>
</tr>
<tr>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("yname")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("ymima")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("daqu")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("dengji")%></td>
<td width="200" height="30" class="font" align="center" valign="middle" bgcolor="#FFFFFF"> <%=rs("cmima")%></td>
</tr>
</table>
<%
rs.movenext
loop%>
<table width="900" border="0" cellspacing="1" cellpadding="0" bgcolor="#fff9e2" frame=box>
<tr>
<td width="900" height="50 align="reft" valign="middle" class="font">
</td>
</tr>
</table> 展开
2个回答
展开全部
给你看一个分页的代码、自己琢磨下、、、
ALTER procedure Consignment
@tablename varchar(80) ,
@strOrder varchar(50) ,
@PageIndex int = 1,
@PageSize int = 15,
@strGetFields varchar(200) = '*',
@OutPut int output
as
Begin
Declare @strSql varchar(500)
DECLARE @SQL NVARCHAR(1000)
DECLARE @R BIGINT
SET @SQL= N'select @R=count(*) from '+@TableName
EXEC SP_EXECUTESQL @SQL, N' @R BIGINT OUTPUT', @R OUTPUT
SET @OutPut= @R
if(@PageIndex =1)
Begin
set @strSql='select top '+str(@PageSize)+' '+@strGetFields+' from '+@tablename+' order by '+@strOrder
End
Else
set @strSql='select top '+str(@PageSize)+' '+@strGetFields+' from '+@tablename+' where ('+@strOrder
+' >= ( select Max('+@strOrder+') from ( select top '+str(@PageSize*@PageIndex)+' * from '+@tablename+' order by '
+@strOrder+' ) as tempTable)) order by '+ @strOrder
select @strSql
exec(@strSql)
End
/// <summary>
/// 分页页码显示
/// </summary>
/// <param name="Numbers">总记录数</param>
/// <param name="Perpage">每页显示几个记录</param>
/// <param name="Curpage">当前页码</param>
/// <param name="Url_Add">链接地址</param>
/// <param name="aname">锚点</param>
/// <param name="ShowPosition">页码显示的位置</param>
/// <param name="SelectStyle">当前页链接样式</param>
/// <param name="Style">其它链接样式</param>
/// <param name="Pages">页面总数</param>
private void MultiPage(int Numbers,
int Perpage,
int Curpage,
string Url_Add,
string aname,
System.Web.UI.HtmlControls.HtmlTableCell ShowPosition,
string SelectStyle,
string Style)
{
string strHTML = null;
string Url = null;
int FromPage, ToPage, Page, Offset,Pages;
Url = Url_Add;
Page = 9;
Offset = 4;
if (Numbers % Perpage == 0)//总页数
{
Pages = Numbers / Perpage;
}
else
{
Pages = Numbers / Perpage + 1;
}
if (Curpage >= Pages) Curpage = Pages;
if (Curpage <= 1) Curpage = 1;
FromPage = Curpage - Offset;
ToPage = Curpage + Page - Offset - 1;
if (Page >= Pages)
{
FromPage = 1;
ToPage = Pages;
}
else
{
if (FromPage < 1)
{
ToPage = Curpage + 1 - FromPage;
FromPage = 1;
if ((ToPage - FromPage) < Page && (ToPage - FromPage) < Pages)
ToPage = Page;
}
else if (ToPage > Pages)
{
FromPage = Curpage - Pages + ToPage;
ToPage = Pages;
if ((ToPage - FromPage) < Page && (ToPage - FromPage) < Pages)
FromPage = Pages - Page + 1;
}
}
if (Curpage != 1)
strHTML += "<a href=\"" + Url + "page=1\" title=\"首页\">首页</a> | ";
if (Curpage != 1)
strHTML += "<a href=\"" + Url + "page=" + (Curpage - 1) + "\" title=\"上一页\">上一页</a> | ";
for (int i = FromPage; i <= ToPage; i++)
{
if (i != Curpage)
{
strHTML += "<a href=\"" + Url + "page=" + i + aname + "\" class=\"" + Style + "\">" + i + "</a> | ";
}
else
{
strHTML += "<span class=\"" + SelectStyle + "\"><strong>" + i + "</strong></span>";
if (i != Pages)
strHTML += " | ";
}
}
if (Curpage != Pages)
strHTML += "<a href=\"" + Url + "page=" + (Curpage + 1) + "\" title=\"下一页\">下一页</a> | ";
if (Curpage != Pages)
strHTML += "<a href=\"" + Url + "page=" + Pages + aname + "\" title=\"尾页\">尾页</a>";
ShowPosition.InnerHtml = strHTML;
}
//调用方式
int currentpage = 1;
if (Request.QueryString["page"] != null)
{
currentpage = Convert.ToUInt16(Request.QueryString["page"].ToString());
}
MultiPage(100, 5, currentpage, "default.aspx?", "",ShowPosition, "", "");
ALTER procedure Consignment
@tablename varchar(80) ,
@strOrder varchar(50) ,
@PageIndex int = 1,
@PageSize int = 15,
@strGetFields varchar(200) = '*',
@OutPut int output
as
Begin
Declare @strSql varchar(500)
DECLARE @SQL NVARCHAR(1000)
DECLARE @R BIGINT
SET @SQL= N'select @R=count(*) from '+@TableName
EXEC SP_EXECUTESQL @SQL, N' @R BIGINT OUTPUT', @R OUTPUT
SET @OutPut= @R
if(@PageIndex =1)
Begin
set @strSql='select top '+str(@PageSize)+' '+@strGetFields+' from '+@tablename+' order by '+@strOrder
End
Else
set @strSql='select top '+str(@PageSize)+' '+@strGetFields+' from '+@tablename+' where ('+@strOrder
+' >= ( select Max('+@strOrder+') from ( select top '+str(@PageSize*@PageIndex)+' * from '+@tablename+' order by '
+@strOrder+' ) as tempTable)) order by '+ @strOrder
select @strSql
exec(@strSql)
End
/// <summary>
/// 分页页码显示
/// </summary>
/// <param name="Numbers">总记录数</param>
/// <param name="Perpage">每页显示几个记录</param>
/// <param name="Curpage">当前页码</param>
/// <param name="Url_Add">链接地址</param>
/// <param name="aname">锚点</param>
/// <param name="ShowPosition">页码显示的位置</param>
/// <param name="SelectStyle">当前页链接样式</param>
/// <param name="Style">其它链接样式</param>
/// <param name="Pages">页面总数</param>
private void MultiPage(int Numbers,
int Perpage,
int Curpage,
string Url_Add,
string aname,
System.Web.UI.HtmlControls.HtmlTableCell ShowPosition,
string SelectStyle,
string Style)
{
string strHTML = null;
string Url = null;
int FromPage, ToPage, Page, Offset,Pages;
Url = Url_Add;
Page = 9;
Offset = 4;
if (Numbers % Perpage == 0)//总页数
{
Pages = Numbers / Perpage;
}
else
{
Pages = Numbers / Perpage + 1;
}
if (Curpage >= Pages) Curpage = Pages;
if (Curpage <= 1) Curpage = 1;
FromPage = Curpage - Offset;
ToPage = Curpage + Page - Offset - 1;
if (Page >= Pages)
{
FromPage = 1;
ToPage = Pages;
}
else
{
if (FromPage < 1)
{
ToPage = Curpage + 1 - FromPage;
FromPage = 1;
if ((ToPage - FromPage) < Page && (ToPage - FromPage) < Pages)
ToPage = Page;
}
else if (ToPage > Pages)
{
FromPage = Curpage - Pages + ToPage;
ToPage = Pages;
if ((ToPage - FromPage) < Page && (ToPage - FromPage) < Pages)
FromPage = Pages - Page + 1;
}
}
if (Curpage != 1)
strHTML += "<a href=\"" + Url + "page=1\" title=\"首页\">首页</a> | ";
if (Curpage != 1)
strHTML += "<a href=\"" + Url + "page=" + (Curpage - 1) + "\" title=\"上一页\">上一页</a> | ";
for (int i = FromPage; i <= ToPage; i++)
{
if (i != Curpage)
{
strHTML += "<a href=\"" + Url + "page=" + i + aname + "\" class=\"" + Style + "\">" + i + "</a> | ";
}
else
{
strHTML += "<span class=\"" + SelectStyle + "\"><strong>" + i + "</strong></span>";
if (i != Pages)
strHTML += " | ";
}
}
if (Curpage != Pages)
strHTML += "<a href=\"" + Url + "page=" + (Curpage + 1) + "\" title=\"下一页\">下一页</a> | ";
if (Curpage != Pages)
strHTML += "<a href=\"" + Url + "page=" + Pages + aname + "\" title=\"尾页\">尾页</a>";
ShowPosition.InnerHtml = strHTML;
}
//调用方式
int currentpage = 1;
if (Request.QueryString["page"] != null)
{
currentpage = Convert.ToUInt16(Request.QueryString["page"].ToString());
}
MultiPage(100, 5, currentpage, "default.aspx?", "",ShowPosition, "", "");
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询