<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      用Asp.net完成新聞分頁

      [摘要]思想:方法是在后臺添加新聞時,估計在應該分頁的地方插入一個標記(我插入的是[PAGE]),在前臺顯示時,我傳入了一個參數Page,表示要顯示第幾頁,在顯示頁面,我根據標記[PAGE]分別把新聞內容放...
      思想:方法是在后臺添加新聞時,估計在應該分頁的地方插入一個標記(我插入的是[PAGE]),在前臺顯示時,我傳入了一個參數Page,表示要顯示第幾頁,在顯示頁面,我根據標記[PAGE]分別把新聞內容放入數組中,如果傳入的參數Page的值是1,我就取Arr[0]的值,如果是第二個......
      還有,我把分頁的html代碼是根據統計的[PAGE]來決定是否顯示的

      BaseInfo是我定義的基本信息類:

      public class BaseInfo
      ?{
      ??public string ID,Summary,Content,Picture;
      ??public DateTime Publictime;

      ??public StringBuilder PageFoot = new StringBuilder();

      ??public BaseInfo()
      ??{?
      ???
      ??}

      ??//添加
      ??public int Add()
      ??{
      ???...??
      ??}

      ??//更新
      ??public int Update()
      ??{
      ???...
      ??}
      ??
      ??//初始化
      ??public void Init()
      ??{
      ???...
      ??}
      ?}


      在這個頁面要傳入兩個參數Page和ID,第一次鏈接到這個頁面傳入的Page值應該是1,而且一定是1,ID是

      新聞的ID,如新聞ID=1的連接應該是BaseInfoDetail.aspx?Page=1&ID=1
      NextAt是后一個[PAGE]的位置,BackAt是前一個[PAGE]標志的位置,PageFoot是一個html表格我加了

      runat=server
      代碼如下:
      BaseInfoDetail.aspx的部分代碼如下:
      BaseInfo info = new BaseInfo();??
      ????info.ID = Request.QueryString["ID"];?
      ????info.Init();

      ????

      //******************************************************************************************

      **********
      ????//分頁
      ????// i:計算標志“[PAGE]”的個數的
      ????//
      ????//???????????????? --? 夢凡? 2004年8月14號19:32
      ????int NextAt = -4,i=0,BackAt = 0;
      ????string[] TempContent = new string[20] ;
      ????do
      ????{
      ?????NextAt += 4;
      ?????NextAt = info.Content.IndexOf("[PAGE]",NextAt);??

      ????????????

      ?
      ?????if(NextAt != -1)
      ?????{
      ??????i++;
      ??????TempContent[i] = info.Content.Substring

      (BackAt,Math.Abs(NextAt-BackAt));
      ??????BackAt = NextAt + 6;
      ?????}
      ????}while(NextAt != -1);
      ??????
      ????int CurrentPage = Convert.ToInt32(Request.QueryString

      ["Page"]);
      ????if(i>0)
      ????{
      ?????info.Content = TempContent[CurrentPage];
      ?????this.PageFoot.Visible = true;
      ????}
      ????else
      ?????this.PageFoot.Visible = false;
      ?????
      ????info.PageFoot.Append("共" +i.ToString()+"頁 ");
      ????for(int j=1;j<=i;j++)
      ????{
      ?????info.PageFoot.Append("[

      href='BaseInfoDetail.aspx?Page=" +j.ToString()+ "&ID=" +info.ID+ "'>" +j.ToString()+ "]

      ");
      ????}
      ????if(CurrentPage != i)
      ????{
      ?????CurrentPage += 1;
      ?????info.PageFoot.Append("下一頁 ");
      ????}
      ????
      ????

      //******************************************************************************************

      **********




      日韩精品一区二区三区高清