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();
    }
  • 相关阅读:
    162. Find Peak Element
    475. Heaters
    字符串统计
    数据的交换输出
    偶数求和
    青年歌手大奖赛_评委会打分
    蟠桃记
    素数判定
    多项式求和
    出现Presentation Error的解决方法
  • 原文地址:https://www.cnblogs.com/Setme/p/2537095.html
Copyright © 2011-2022 走看看