zoukankan      html  css  js  c++  java
  • 分页

    //DAL层

    public List<studentModel> show(string name = "",int index=1,int size=2)
    {
    int start = (index - 1) * size + 1;
    int end = start + size - 1;
    string sql = string.Format("select * from (select *,ROW_NUMBER()over(order by id)px from student where name like '%{0}%')t where t.px between {1}and {2}",name,start,end);
    var n = db.GetDataTable(sql);
    var list = JsonConvert.SerializeObject(n);
    var table = JsonConvert.DeserializeObject<List<studentModel>>(list);
    return table;
    }
    public int count()
    {
    string sq = "select count(id) from student";
    var i = db.ExecuteScalar(sq);
    return i;
    }

    //控制器
    public ActionResult Index(string name = "",int index=1,int size=2)
    {
    ViewBag.index = index;
    int count = st.count();
    ViewBag.count = Math.Ceiling(count * 1.0 / size);
    var n = st.show(name,index,size);
    return View(n);
    }

    ////显示视图

    <input id="index" type="hidden" value="@ViewBag.index" />
    <input id="count" type="hidden" value="@ViewBag.count" />
    <input id="Button1" type="button" value="首页" onclick="sy()" />
    <input id="Button1" type="button" value="上一页" onclick="syy()" />
    <input id="Button1" type="button" value="下一页" onclick="xyy()" />
    <input id="Button1" type="button" value="尾页" onclick="wy()" />

    <script>
    var index = 1;
    var size = 2;
    function sy() {
    location.href = "/student/Index?index=1&size=2";
    }
    function syy() {
    index = $("#index").val();
    index <= 1 ? 1 : index--;
    location.href = "/student/Index?index=" + index + "&size=" + size + "";
    }
    function xyy() {
    index = $("#index").val();
    var count = $("#count").val();
    index >= count ? count : index++;
    location.href = "/student/Index?index=" + index + "&size=" + size + "";
    }
    function wy() {
    index = $("#count").val();
    location.href = "/student/Index?index=" + index + "&size=" + size + "";
    }
    </script>

  • 相关阅读:
    树莓派配置Jdk环境并设置开机启动jar
    缓存架构之路(一)缓存概述及应用
    并发编程学习历程(零)JMM内存模型
    并发编程学习历程(一)Synchronized
    深入Disruptor源码分析(一)入门指南
    JAVA Synchronized和Lock实现原理
    Vscode断点调试PHP
    php环境搭建
    github使用总结
    面试笔记
  • 原文地址:https://www.cnblogs.com/gaoyuhui/p/10957298.html
Copyright © 2011-2022 走看看