欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP无组件分页实现思路及代码

程序员文章站 2022-08-10 17:51:16
mvc下: 后台代码: 复制代码 代码如下: public actionresult sys(string page) { if (page == null) { stri...
mvc下:
后台代码:
复制代码 代码如下:

public actionresult sys(string page)
{
if (page == null)
{
string sql = "select top 15 * from dingdinfo order by dingdh desc";
viewdata["ds"] = dr.resultset(sql, "dingdinfo");
}
if (page != null)
{
int pagesl = convert.toint32(page);
string sql = "select top 15 * from dingdinfo where id not in (select top " + (pagesl - 1) * 15 + " id from dingdinfo order by dingdh desc )order by dingdh desc";
viewdata["ds"] = dr.resultset(sql, "dingdinfo");
}
//计算pagecount
string sql1 = "select * from dingdinfo";
int pagecount = dr.resultcount(sql1,"dingdinfo");
int chu = convert.toint32(pagecount / 15);
int yus = convert.toint32(pagecount % 15);
if (pagecount > 15)
{
int pagejg = chu;
if (yus != 0)
{
pagejg = chu + 1;
viewdata["jg"] = pagejg;
}
else
{
viewdata["jg"] = pagejg;
}
}
return view();
}

页面显示:
js代码:
复制代码 代码如下:

<script type="text/javascript">
//分页
function page(id) {
window.location = "/bookindex/sys/?page=" + id;
}
</script>

html代码:
复制代码 代码如下:

<td>
<% int count =convert.toint32(viewdata["jg"]);
if (count != 0)
{
for (int i = 1; i <=count; i++)
{ %>
<a href = "#" onclick="page(<%:i%>)"><%:i%></a>
<% }
}%>
</td>

页面最终效果:
ASP无组件分页实现思路及代码