zoukankan      html  css  js  c++  java
  • JqueryPager+ashx 实现分页

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="study._Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript" language="javascript" src="jquery-pager/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" language="javascript" src="jquery-pager/jquery.pager.js"></script>
        <link rel="Stylesheet" type="text/css" href="jquery-pager/Pager.css" />
        <script type="text/javascript">
            var pagecount;
            $(document).ready(function () {
                $.get("Handler.ashx", { type: 1, pagesize: 10, index: 1 }, function (data, textStatus) {
                    pagecount = data;
                    $("#pager").pager({ pagenumber: 1, pagecount: pagecount, buttonClickCallback: PageClick });
                });
                Go(1);
            });
            PageClick = function (pageclickednumber) {
                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
                Go(pageclickednumber);
            }
            function Go(index) {
                $("#Content").html("");
                $.getJSON("Handler.ashx", { type: 0, pagesize: 10, index: index }, function (data) {
                    $("#Content").append("<tr><th style='130px'>ID</th><th style='150px'>Name</th><th style='150px'>ClassName</th></tr>");
                    $.each(data, function (i, k) {
                        $("#Content").append("<tr><td>" + data[i].id + "</td><td>" + data[i].Name + "</td><td>" + data[i].ClassName + "</td></tr>");
                    })
                });
            }
         </script>
    
    
    </head>
    <body>
        <form id="form1" runat="server">
          <div style=" 100%" id="abc">
               <table id="Content" >                         
               </table>
               <div id="pager" ></div>
            </div>    
        </form>
    </body>
    </html>









      public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                int pageSize = int.Parse(context.Request.Params["pagesize"]); //每页记录数
                int pageIndex = int.Parse(context.Request.Params["index"]);  //当前页索引    
                int type = int.Parse(context.Request.Params["type"]); //1为获取总页数,0为获取分页数据          

                if (type == 1)
                {
                    int recordCount = GetRecordCount("select count(*) from MyTest");
                    int pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(recordCount) / pageSize));
                    string str = pageCount.ToString();
                    context.Response.Write(str);
                }
                else
                {
                    string sql = string.Format("select id,Name,ClassName from ( select row_number() over (order by id) as rowNum,* from MyTest) as t "
                        + " where rowNum>{0} and rowNum<={1}", (pageIndex - 1) * pageSize, pageIndex * pageSize);
                    System.Data.DataTable dt = Getds(sql).Tables[0];
                    string str = "[" + JsonHelper.DataTableToJSON(dt) + "]";
                    context.Response.Write(str);
                }
            }
            public int GetRecordCount(string sql)
            {
                SqlConnection conn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=test;Integrated Security=True");
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                return Convert.ToInt32(cmd.ExecuteScalar().ToString());
            }
            public DataSet Getds(string sql)
            {
                SqlConnection conn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=test;Integrated Security=True");
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                DataSet ds = new DataSet();
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                adp.Fill(ds);
                return ds;
            }
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }

  • 相关阅读:
    结合中断上下文切换和进程上下文切换分析Linux内核的一般执行过程--课程实验3
    深入理解系统调用 -- 课程实验2
    基于mykernel 2.0编写一个操作系统内核--课程实验1
    如何评测软件工程知识技能水平?
    如何评测一个软件工程师的计算机网络知识水平与网络编程技能水平?
    深入理解TCP协议及其源代码
    Socket与系统调用深度分析
    创新产品的需求分析:未来的图书是什么样的
    构建调试Linux内核网络代码的环境MenuOS系统
    php db2 返回当前insert记录的自增id
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2642412.html
Copyright © 2011-2022 走看看