新闻内容实现分页
/// <summary>
/// 新闻内容分页
/// </summary>
/// <param name="content">新闻内容</param>
/// <param name="extension">扩展名(aspx,html..)</param>
/// <returns></returns>
public string NewsContentPager(string content,string extension)
{
string p = "\\[page\\]";
if (content.IndexOf("[page]") != -1)
{
string page = Request.QueryString["page"];
string[] arrContent = Regex.Split(content,p,RegexOptions.IgnoreCase);
int pageSize = arrContent.Length;
if (String.IsNullOrEmpty(page))
page = "0";
if (int.Parse(page) >= pageSize)
{
Response.StatusCode = 404;
Response.End();
}
//生成分页页码
StringBuilder sb = new StringBuilder();
sb.Append(arrContent[int.Parse(page)].ToString());
sb.Append("<div id=\"newspager\" style=\"margin:5px 0px 5px 0px;\">");
if (int.Parse(page) > 0)
sb.AppendFormat("<a href=\"{0}_{1}.{2}\">上一页</a>", Request.QueryString["id"],int.Parse(page)-1,extension);
for (int i = 0; i < pageSize; i++)
{
if (i == int.Parse(page))
sb.AppendFormat("<span>{0}</span>", i + 1);
else
sb.AppendFormat("<a href=\"{0}_{1}.{3}\">{2}</a>", Request.QueryString["id"], i, i + 1,extension);
}
if (int.Parse(page) < pageSize-1)
sb.AppendFormat("<a href=\"{0}_{1}.{2}\">下一页</a>", Request.QueryString["id"], int.Parse(page)+1,extension);
sb.Append("</div>");
return sb.ToString() ;
}
return content;
}
/// 新闻内容分页
/// </summary>
/// <param name="content">新闻内容</param>
/// <param name="extension">扩展名(aspx,html..)</param>
/// <returns></returns>
public string NewsContentPager(string content,string extension)
{
string p = "\\[page\\]";
if (content.IndexOf("[page]") != -1)
{
string page = Request.QueryString["page"];
string[] arrContent = Regex.Split(content,p,RegexOptions.IgnoreCase);
int pageSize = arrContent.Length;
if (String.IsNullOrEmpty(page))
page = "0";
if (int.Parse(page) >= pageSize)
{
Response.StatusCode = 404;
Response.End();
}
//生成分页页码
StringBuilder sb = new StringBuilder();
sb.Append(arrContent[int.Parse(page)].ToString());
sb.Append("<div id=\"newspager\" style=\"margin:5px 0px 5px 0px;\">");
if (int.Parse(page) > 0)
sb.AppendFormat("<a href=\"{0}_{1}.{2}\">上一页</a>", Request.QueryString["id"],int.Parse(page)-1,extension);
for (int i = 0; i < pageSize; i++)
{
if (i == int.Parse(page))
sb.AppendFormat("<span>{0}</span>", i + 1);
else
sb.AppendFormat("<a href=\"{0}_{1}.{3}\">{2}</a>", Request.QueryString["id"], i, i + 1,extension);
}
if (int.Parse(page) < pageSize-1)
sb.AppendFormat("<a href=\"{0}_{1}.{2}\">下一页</a>", Request.QueryString["id"], int.Parse(page)+1,extension);
sb.Append("</div>");
return sb.ToString() ;
}
return content;
}