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(); }