2007年5月29日

程 序

Tags:

长文章分页程序(根据设定标记)

//分页类
public static string PageInfo(int count, string pageInfo, int pageList, int nowPage, string pageStr, string unit)
  {
   int pageCount = 1;
   string temp = "<font color='red'>" + pageInfo + "共有" + count + unit + "</font>&nbsp;" + "每页" + pageList + unit + pageInfo;
   if (count > 0)
   {
    string firstPage = "";//首页
    string lastPage = "";//上一页
    string nextPage = "";//下一页
    string endPage = "";//未页
    pageCount = count / pageList;
    string selectStr = "跳转:<select name='PageSelect' onchange='window.location.href=value' id='PageSelect'>";//下拉单
    if ((count % pageList) > 0)
    {
     pageCount++;
    }
    for (int i = 1; i <= pageCount; i++)
    {
     if (i == nowPage)
     {
      selectStr += "<option selected='selected' value='" + pageStr + "page=" + i + "'>" + i + "</option>";
     }
     else
     {
      selectStr += "<option value='" + pageStr + "page=" + i + "'>" + i + "</option>";
     }
    }
    selectStr += "</select>";
    if (pageCount == 1)
    {
     firstPage = "<font color='#cccccc'>首页</font>";
     lastPage = "<font color='#cccccc'>上一页</font>";
     nextPage = "<font color='#cccccc'>下一页</font>";
     endPage = "<font color='#cccccc'>尾页</font>";
    }
    else
    {
     if (nowPage == 1)
     {
      firstPage = "<font color='#cccccc'>首页</font>";
      lastPage = "<font color='#cccccc'>上一页</font>";
      nextPage = "<a href='" + pageStr + "page=" + (nowPage + 1) + "'>下一页</a>";
      endPage = "<a href='" + pageStr + "page=" + pageCount + "'>尾页</a>";
     }
     else if (nowPage == pageCount)
     {
      firstPage = "<a href='" + pageStr + "page=1'>首页</a>";
      lastPage = "<a href='" + pageStr + "page=" + (pageCount - 1) + "'>上一页</a>";
      nextPage = "<font color='#cccccc'>下一页</font>";
      endPage = "<font color='#cccccc'>尾页</font>";
     }
     else
     {
      nextPage = "<a href='" + pageStr + "page=" + (nowPage + 1) + "'>下一页</a>";
      lastPage = "<a href='" + pageStr + "page=" + (nowPage - 1) + "'>上一页</a>";
      firstPage = "<a href='" + pageStr + "page=1'>首页</a>";
      endPage = "<a href='" + pageStr + "page=" + pageCount + "'>尾页</a>";
     }
    }
    temp += "&nbsp;&nbsp;" + firstPage + "&nbsp;&nbsp;" + lastPage + "&nbsp;&nbsp;" + nextPage + "&nbsp;&nbsp;" + endPage + "&nbsp;&nbsp;" + selectStr;
   }
   else
   {
    temp = "";
   }
   return temp;
  }

//实现代码

    int page = 1;
    if (Request.QueryString["page"] != null)
    {
     page = Convert.ToInt32(Request.QueryString["page"].Trim());
    }

    int ArticleID = Convert.ToInt16(Request["ID"]);
    dr = MyclassDA.Index_Article_Show(ArticleID);  //SqlDataReader Index_Article_Show(int ID) 创建对象 
    dr.Read();

    show1.InnerHtml = dr["Title"].ToString();
    string content = dr["Content"].ToString();
    ArrayList body = new ArrayList();

    string PageStr = "a_read.aspx?id="+ArticleID+"&";

    if (content.IndexOf("{#NextPage#}") > -1)//存在分页符号则分页
    {
     //string[] tempList = content.Split(new string[] { "{@Next@}" }, StringSplitOptions.RemoveEmptyEntries);//String.Split 2.0新增特性
     //string[] tempList = SplitPage(content,"{@Next@}");//内容分页
     string[] tempList = Regex.Split(content,"{#NextPage#}",RegexOptions.IgnoreCase);
     for (int i = 0; i<tempList.Length; i++)
     {
      body.Add(tempList[i]);
     }
    
    }
    else
    {
     body.Add(content);//直接输出内容
    }

    if (page < 1 || page > body.Count)
    {
     page = 1;
    }

    if (body.Count == 1)
    {
     l_content.InnerHtml = (string)body[0];
    }
    else
    {
     if (page <= body.Count)
     {
      l_content.InnerHtml = (string)body[page - 1];
     }
     else
     {
      l_content.InnerHtml = (string)body[0];
     }
    }

    MyCutePage.InnerHtml= CommonClass.PageInfo(body.Count, "新闻", 1, page, PageStr, "篇");
 
    dr.Close();

  • 本文是由小屋漏雨发表于2007-5-29 9:30:25

    已被浏览 次,引用0次和1个评论

    这是Trackback地址  欢迎发表评论 ^_^

  • 相关文章:

1个评论

1

luyap 2007-6-24 9:53:27 reply
谢谢了,搞定