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>

  • 相关阅读:
    Atom,AtomPub 和Java 转载
    使用OData协议查询Windows日志 转
    许可协议BSD GPL MPL LGPL APL转载
    Eclipse Galileo 简介
    常见证书格式和转换
    JVM简介转
    Android Native 代码开发学习笔记转载
    echarts——各个配置项详细说明总结
    Mysql 安装服务无法启动解决方案与使用的一般使用指令
    js中如何把字符串(文本)转化为对象
  • 原文地址:https://www.cnblogs.com/gaoyuhui/p/10957298.html
Copyright © 2011-2022 走看看