您的位置:首页 > 编程语言 > ASP

AspNetPager 新闻内容分页

2013-05-13 14:16 309 查看
前台:

<%if (YesIsNoPage)

{%>

<webdiyer:AspNetPager ID="AspNetPager" CssClass="paginator" CurrentPageButtonClass="cpb"

runat="server" AlwaysShow="True" FirstPageText="Home" LastPageText="End" NextPageText="Next"

PageSize="1" PrevPageText="Previous" OnPageChanged="AspNetPager_PageChanged"

CustomInfoTextAlign="Center" LayoutType="Table" ShowPageIndex="false" CustomInfoHTML="Current: %CurrentPageIndex%/%PageCount% Pages"

PageIndexBoxType="TextBox" ShowCustomInfoSection="Left" ShowPageIndexBox="Never">

</webdiyer:AspNetPager>

<% } %>

后台:

protected static string ProductsText;

protected static bool YesIsNoPage;

protected static string strContent;

protected void Products_load()

{

string text = ProductsText;

//查找分页符并替换html标签

string StringB = "<div style=\"page-break-after: always\"> <br /> <span style=\"display: none;\"> </span></div>"; text = text.Replace("\n\t", "");

text = text.Replace("\n", "<br />");

text = text.Replace("\r", " ");

string[] strLined = text.Split(new string[] { StringB }, StringSplitOptions.RemoveEmptyEntries);

string tempString = null;

this.AspNetPager.RecordCount = strLined.Length;

int PageSize = this.AspNetPager.PageSize;

int PageIndex = this.AspNetPager.CurrentPageIndex;

//判断是否显示分页控件

if (strLined.Length > 1)

YesIsNoPage = true;

else

YesIsNoPage = false;

//判断是否启动分页

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 />";

}

strContent = tempString;

}

else

{

for (int i = (PageIndex - 1) * PageSize; i < JudgeNoPage; i++)

{

tempString += strLined[i] + "<br />";

}

strContent = tempString;

}

}

protected void AspNetPager_PageChanged(object sender, EventArgs e)

{

Products_load();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: