• ajax分页


    ajaxLD.aspx.cs

    public partial class userCenter_ajaxLD : CenterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int ee3 = DNTRequest.GetFormInt("ee3", 0);
            if (ee3 > 0)
            {
                int ee1 = DNTRequest.GetFormInt("ee1", 0);
                int ee2 = DNTRequest.GetFormInt("ee2", 1);
                int count = 0;
                int pagesize = 5;
                if (ee1 == 1)
                {
                    DataTable dt = AllTableHelp.GetAllInfo("(select m.Truename nc,m.Imgpath tx,m.State mstate,ld.* from h_message ld left join h_member m on ld.refMID=m.MID) tb1",
                        "*", "Createdate", true, pagesize, ee2, " and mstate=1 and refThis=" + ee3, out count);
                    if (dt.Rows.Count > 0)
                    {
                        int i = 0;
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (i % 2 == 0)
                            {
                                sb.Append("<div class=\"neio\" style=\"margin-top: 11px;\"><dl><dt><img src=\"" + ResolveUrl("~/"));
                                sb.Append(dr["tx"] + "\" width=\"30\" height=\"31\" /></dt><dd><a href=\"#0\">");
                                sb.Append(dr["refMID"].ToString() == userid.ToString() ? "我说" : dr["nc"]);
                                sb.Append("</a>" + dr["contents"] + "</dd><dd style=\"float: left; color: #a1a1a1; float: right;  505px;\">");
                                sb.Append(Convert.ToDateTime(dr["Createdate"]).ToString("yyyy年MM月dd日 HH:mm") + "</dd></dl></div>");
                            }
                            else
                            {
                                sb.Append("<div class=\"neio\" style=\"margin-top: 21px;\"><dl><dt><img src=\"" + ResolveUrl("~/"));
                                sb.Append(dr["tx"] + "\" width=\"30\" height=\"31\" /></dt><dd><a href=\"#0\">");
                                sb.Append(dr["refMID"].ToString() == userid.ToString() ? "我说" : dr["nc"]);
                                sb.Append("</a>" + dr["contents"] + "</dd><dd style=\"float: left; color: #a1a1a1; float: right;  505px;\">");
                                sb.Append(Convert.ToDateTime(dr["Createdate"]).ToString("yyyy年MM月dd日 HH:mm") + "</dd></dl></div>");
                            }
                            i++;
                        }
                        if (count > pagesize)
                            sb.Append(getPageNum(count, pagesize, ee2, ee1, ee3));
                    }
                }
                else if (ee1 == 2)
                {
    
                }
                else if (ee1 == 3)
                {
    
                }
            }
            Response.Write(sb);
            Response.End();
        }
    
        private string getPageNum(int total, int pagesize, int page, int ee1, int ee3)
        {
            if (page < 1)
                page = 1;
            var allpage = 0;
            var next = 0;
            var pre = 0;
            var startcount = 0;
            var endcount = 0;
            var pagestr = "";
            var sjStr = " href=\"#0\" onclick=\"yb_ld(" + ee1 + ",";
            if (page < 1)
                page = 1;
            if (pagesize != 0)
            {
                allpage = Convert.ToInt32(total / pagesize);
                allpage = Convert.ToInt32((total % pagesize) != 0 ? allpage + 1 : allpage);
                allpage = Convert.ToInt32(allpage == 0 ? 1 : allpage);
            }
            next = page + 1;
            pre = page - 1;
            startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
            //中间页终止序号
            endcount = page < 5 ? 10 : page + 5;
            if (startcount < 1)
                startcount = 1;//为了避免输出的时候产生负数,设置如果小于1就从序号1开始
            if (allpage < endcount)
                endcount = allpage;//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内
            pagestr += "<div class=\"divPInfo\">共<span>" + total + "</span>条记录&nbsp;&nbsp;&nbsp;&nbsp;每页<span>"
                + pagesize + "</span>条&nbsp;&nbsp;&nbsp;&nbsp;共<span>" + allpage + "</span>页</div>";
            pagestr += "<div class=\"pagelist\">";
            pagestr += "<ul>";
            if (page > 1)
                pagestr += "<li><a" + sjStr + "1," + ee3 + ");\">首页</a></li><li><a" + sjStr + pre + "," + ee3 + ");\">上一页</a></li>";
            //else
            //    pagestr += "<li class=\"bjy\">首页</li><li class=\"bjy\">上一页</li>";
            //中间页处理,这个增加时间复杂度,减小空间复杂度
            for (var i = startcount; i <= endcount; i++)
            {
                if (page == i)
                    pagestr += "<li class=\"current\">" + i + "</li>";
                else
                    pagestr += "<li><a" + sjStr + +i + "," + ee3 + ");\">" + i + "</a></li>";
            }
            if (page != allpage)
                pagestr += "<li><a" + sjStr + next + "," + ee3 + ");\">下一页</a></li><li><a" + sjStr + allpage + "," + ee3 + ");\">末页</a></li>";
            //else
            //    pagestr += "<li class=\"bjy\">下一页</li><li class=\"bjy\">末页</li>";
            pagestr += "</ul>";
            pagestr += "</div>";
    
            return pagestr;
        }
    
    }
    $(function(){    
        $("div[cc]").each(function(i){
            yb_ld(1, 1, $(this).attr("cc"));
        });
    });
    function yb_ld(ee1, ee2, ee3){//类型,第几页,对应的id下的
        $.ajax({
            type : "POST",
            url : 'ajaxLD.aspx',
            data : {"ee1" : ee1, "ee2" : ee2, "ee3" : ee3},
            beforeSend : function(xmlHttpRequest){
                //$("div[cc='" + ee3 + "']").html("<img src='../images/loading.gif' />");
            },
            success : function(data,textStatus){
                $("div[cc='" + ee3 + "']").html(data);
            },
            complete : function(xmlHttpRequest, textStatus){            
            },
            error : function(){
            }
        });
    }
    function tjfy(ee1, ee2){
        var bcsr = $.trim(ee1);
        if(bcsr.length < 1){
            alert("请输入页码");
            return false;
        }        
        var newPar = /^\d+$/;
        if(!newPar.test(bcsr)){
            alert("页码只能输入正整数");
            return false;
        }
        if(ee1 < 1){
            alert("页码最小只能输入1");
            return false;
        }
        if(parseInt(ee2) < parseInt(ee1)){
            alert("页码最大只能输入" + ee2);
            return false;
        }
    }
    function fkfy(){
        return tjfy($("#txtPageFKGo").val(), $("#hfFKIndex").val());
    }
  • 相关阅读:
    crontab自动备份MySQL数据库并删除5天前备份
    使用ShowDoc在线管理API接口文档
    概率计算(抽奖活动、命中率)
    保护隐私?找回已记住的秘密?你的余额宝、淘宝还安全吗?
    自制公众平台Web Api(微信)
    我为什么期待M#?
    在.net中为什么第一次执行会慢?
    记”Uri.IsWellFormedUriString”中的BUG
    公司ERP系统重构那些事
    Koala Framework是什么?我为什么要写这个框架?
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768342.html
Copyright © 2020-2023  润新知