zoukankan      html  css  js  c++  java
  • 利用AspNetPager进行文章内分页(用回车次数来判断分页)

    aspx:

     <webdiyer:AspNetPager ID="AspNetPager" CssClass="paginator" CurrentPageButtonClass="cpb"
              runat="server" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页"
              PageSize="21" PrevPageText="上一页" OnPageChanged="AspNetPager_PageChanged" CustomInfoTextAlign="Center"
              LayoutType="Table" ShowPageIndex="false" PageIndexBoxType="TextBox" ShowPageIndexBox="Never"
              SubmitButtonText="Go" TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到">
     </webdiyer:AspNetPager>

    cs:

    protected static string NewsContent;
    protected static string NewsTitle;
    protected static int id;       
    private void News_load()
    {
        string strSql = "select NewsTitle,NewsContent from News where id=" + id + " and NewsIsInvisible=0";
        DataSet ds = Tool.DataAccess.dataSet(strSql);
        string text = ds.Tables[0].Rows[0]["NewsContent"].ToString();
        NewsTitle = ds.Tables[0].Rows[0]["NewsTitle"].ToString();
        //查找分页符并替换html标签
         string StringS = "\n\t", StringE = "<br />";
        text = text.Replace("\n\t", "");
        text = text.Replace("\n", "<br />");
        text = text.Replace("<div>", "");
        text = text.Replace("</div>", "");
        string[] strLined = text.Split(new string[] { StringE }, StringSplitOptions.RemoveEmptyEntries);
        //end
        string tempString = null;
        this.AspNetPager.RecordCount = strLined.Length;
        int PageSize = this.AspNetPager.PageSize;
        int PageIndex = this.AspNetPager.CurrentPageIndex;
        //判断是否启动分页
         int JudgeYesPage = strLined.Length / PageSize + 1;
        int JudgeNoPage = strLined.Length;
        if (this.AspNetPager.CurrentPageIndex != JudgeYesPage)
        {
            for (int i = (PageIndex - 1) * PageSize; i < PageSize * PageIndex; i++)
            {
                tempString += strLined[i] + "<br />";
            }
            NewsContent = tempString;
        }
        else
        {
            for (int i = (PageIndex - 1) * PageSize; i < JudgeNoPage; i++)
            {
                 tempString += strLined[i] + "<br />";
            }
            NewsContent = tempString;
        }
        ds.Dispose();
    }
    
    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        News_load();
    }
  • 相关阅读:
    JavaScript自动化构建工具grunt、gulp、webpack介绍
    开始使用 Vuejs 2.0 ---简单总结2
    开始使用 Vuejs 2.0 ---简单总结1
    Bootboxjs快速制作Bootstrap的弹出框效果
    FlexSlider是一个非常出色的jQuery滑动切换插件
    CSS实现背景透明,文字不透明(兼容各浏览器)
    jquery中attr和prop的区别
    GitHub 的分支创建与合并
    [译]使用NuGet管理共享代码
    [译]Nuget.Server
  • 原文地址:https://www.cnblogs.com/Setme/p/2537095.html
Copyright © 2011-2022 走看看