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;
                }
            }

  • 相关阅读:
    解决win7和win8的64位系统安装NetAdvantage时总是提示%SystemDriver%inetpub\wwwroot错误的方法
    如何使VS2008 调试网站的根目录和IIS调试的一致?
    设置网站默认目录
    asp.net网站未能加载文件或程序集或它的某一个依赖项。拒绝访问
    HTML5 :Canvas之基本用法
    HTML5 Canvas之图片引用
    python虚拟环境的介绍和创建
    基于jTemplates、ascx协同工作的酷UI模板技术
    我的.Subtext二次开发之路系列:无限层次分类
    我的.Subtext二次开发之路系列:引言
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2642412.html
Copyright © 2011-2022 走看看