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>
页面最终效果:
后台代码:
复制代码 代码如下:
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正则替换链接实现伪静态效果