zoukankan      html  css  js  c++  java
  • 将数据库中提取出来的数据在后台进行分页处理

    CDataManage objdm = new CDataManage();
        string sSql = "";
        int page = 1;
        string html = "";
        DataTable dt = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            sSql = "select * from apps with(nolock) order by created desc";
            dt = objdm.GetDataTableBySQL(sSql);
            html = "";
            if (Request["page"] != null && Request["page"].ToString() != "")
            {
                page = Convert.ToInt32(Request["page"].ToString());
            }
    //分页的页数
            if (dt.Rows.Count > 0)
            {
                int pagenum = (dt.Rows.Count - 1) / 10 + 1;
                if (page == 1)
                {
                    html += "<a style="margin-right:15px;color:#888;text-decoration:none;">上一页</a>";
                }
                else
                {
                    html += "<a href="CheckSift.aspx?page=" + (page - 1) + "" style="margin-right:15px;">上一页</a>";
                }
                html += "<select onchange="window.location=this.value;">";
                for (int i = 0; i < pagenum; i++)
                {
                    int a = i + 1;
                    if (page == a)
                    {
                        html += "<option selected="selected" value="CheckSift.aspx?page=" + a + "">" + a + "</option>";
                    }
                    else
                    {
                        html += "<option value="CheckSift.aspx?page=" + a + "">" + a + "</option>";
                    }
                }
                html += "</select>";
                if (page == pagenum)
                {
                    html += "<a style="margin-left:15px;color:#888;text-decoration:none;">下一页</a>";
                }
                else
                {
                    html += "<a href="CheckSift.aspx?page=" + (page + 1) + "" style="margin-left:15px;">下一页</a>";
                }
            }
            fenye.InnerHtml = html;
            ShowMessage();
        }
     
    //分页显示信息
        public void ShowMessage()
        {
            html = "";
            if (dt.Rows.Count > 0)
            {
                string sift = "False";
                string time = "";
                int irank = (page - 1) * 10;
                for (int i = 0; i < 10; i++)
                {
                    if (irank < dt.Rows.Count)
                    {
                        sift = dt.Rows[irank]["issift"].ToString();
                        time = dt.Rows[irank]["created"].ToString();
                        html += "<li>";
                        html += "<input type='text' class='sift' value='" + dt.Rows[irank]["id"].ToString() + "' style='display:none;'>";
                        html += "<span class='title'>作品名称:" + dt.Rows[irank]["title"].ToString() + "</span><span class='line'></span>";
                        html += "<span class='creator'>发布人:" + dt.Rows[irank]["creator"].ToString() + "</span><span class='line'></span>";
                        html += "<span class='created'>发布时间:" + time.Substring(0, 10) + "</span><span class='line'></span>";
                        if (sift=="True") {
                            html += "<span>是否精选:<input disabled='disabled' checked='checked' type='checkbox' /></span>";
                        }
                        else {
                            html += "<span>是否精选:<input type='checkbox' onclick='IsSift(this)' /></span>";
                        }
                        html += "</li>";
                    }
                    irank++;
                }
                list.InnerHtml = html;
            }
        }
  • 相关阅读:
    Collections之sort、reverse
    网页小实验——在平面空间建立大量“可思考的”对象
    3D网页小实验——将txt配置文本转化为3D陈列室
    原生JavaScript实现一种日历
    JavaScript实现竖向滚动条的一种思路
    一个原生JavaScript动画库原型
    html小工具——文章注释编辑器
    基于Babylon.js编写宇宙飞船模拟程序1——程序基础结构、物理引擎使用、三维罗盘
    WebGL场景的两种地面构造方法
    基于Babylon.js编写简单的骨骼动画生成器
  • 原文地址:https://www.cnblogs.com/zhongzunmu/p/5430035.html
Copyright © 2011-2022 走看看