将数据库中提取出来的数据在后台进行分页处理

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 οnchange=\"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' οnclick='IsSift(this)' /></span>";
                    }
                    html += "</li>";
                }
                irank++;
            }
            list.InnerHtml = html;
        }
    }

转载于:https://www.cnblogs.com/zhongzunmu/p/5430035.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值