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

  • 相关阅读:
    flash动态加载多张图片
    使用ASPJPEG添加水印的方法
    利用数据库复制技术 实现数据同步更新
    ASP.NET 2.0中发送电子邮件
    .net2.0 自定义CheckBoxList验证控件
    c#动态创建存储过程中,提示'go' 附近有语法错误解决方案
    MSDB数据库置疑状态的解决方法
    ASP.NET发送邮件_相关参数
    SQL数据库msdb置疑(急)
    SQL2000数据库脱机/只读/紧急模式 修复
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2642412.html
Copyright © 2020-2023  润新知