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>

  • 相关阅读:
    创业日记-时间过的也快也慢
    通过获取客户端Json数据字符串,反序列化为实体对象的一段代码
    Sandcastle是什么
    使用VisualSVN Server自动发布站点
    Microsoft Visual Studio Ultimate 2015 Preview使用笔记
    俞敏洪:自卑比狂妄更糟糕
    灰度发布
    TLV格式是什么格式
    zend studion实现自动换行
    数字格式化,从右往左每隔三位加逗号的四种方法
  • 原文地址:https://www.cnblogs.com/gaoyuhui/p/10957298.html
Copyright © 2011-2022 走看看