一個比較好看的網頁翻頁效果_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:使用存儲過程實現用戶登錄(含代碼)
      程序代碼: public SqlDataReader GetUserLoginByProc(string sUserName,string sPassword) { ///創建鏈接 SqlConnection myConnection = new SqlConnection( ConfigurationManager.ConnectionStrings[數據庫連接字符].ConnectionString); ///創建Command S

      顯示效果:1 2 3 4 5>> ,點擊了4后又顯示 ,4 5 6 7 8>>并轉到第4頁 ,如果總共有10頁,  顯示到6 7 8 9 10>>就不再顯示了。

      .aspx

      <tr> <td align="center"><div class="tbl">
                  【當前頁:<asp:Label ID="lblcurpg" runat="server"></asp:Label> |  總記錄數:<asp:Label ID="lblRecord" runat="server"></asp:Label>】 
              <%=strpg %>
          </div></td>
              </tr>

      .cs

      protected string strpg = string.Empty;
             
      protected string strUrl = "aa.aspx";
             
      protected int PgSize = 15;
             
      protected string wherestr = string.Empty;
             
      protected void Page_Load(object sender, EventArgs e)
              {
                 
      if (!Page.IsPostBack)
                  {
                     
      int curpg = GetIdx();
                     
      if (Request.QueryString["val"] != null)
                      {
                          wherestr
      = Request.QueryString["val"].ToString();
                         
      string strVal = "where NewsTitle like '%" + wherestr + "%' ";
                          Prepg(curpg, strVal);
                      }
                     
      else
                      {
                          Prepg(curpg, wherestr);
                      }

                       }
              }

             
      #region 加載頁面
             
      protected void Prepg(int Idx, string strWhere)
              {
                  .....
      //獲取一個dataset
                  int RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0].ItemArray[0].ToString());
                  strpg
      = Getpgstr(RecordCount, PgSize, Idx, strUrl);
                  lblcurpg.Text
      = Idx.ToString();
                  lblRecord.Text
      = RecordCount.ToString();
              }
             
      #endregion

             
      #region 獲取分頁控件
             
      protected string Getpgstr(int total, int per, int page, string query_string)
              {
                 
      return pagination(total, per, page, query_string);
              }
             
      #endregion

             
      protected void btnSearch_Click(object sender, EventArgs e)
              {
                  Response.Redirect(strUrl
      + "?val=" + txtNew.Text);
              }

             
      #region 獲取當前頁
             
      protected int GetIdx()
              {
                 
      int curpg;
                 
      if (Request.QueryString["page"] == null)
                  {
                      curpg
      = 1;
                  }
                 
      else
                  {
                      curpg
      = Convert.ToInt32(Request.QueryString["page"].ToString());
                  }
                 
      return curpg;
              }
             
      #endregion 
      public static string pagination(int total, int per, int page, string query_string)
              {
                 
      //page表是當前頁
                 
      //per表示每頁顯示記錄數
                  int allpage = 0;
                 
      int next = 0;
                 
      int pre = 0;
                 
      int startcount = 0;
                 
      int endcount = 0;
                 
      string pagestr = "";
                 
      if (page < 1) { page = 1; }
                 
      //計算總頁數
                  if (per != 0)
                  {
                      allpage
      = (total / per);
                      allpage
      = ((total % per) != 0 ? allpage + 1 : allpage);
                      allpage
      = (allpage == 0 ? 1 : allpage);
                  }
                  next
      = page + 1;
                  pre
      = page - 1;
                  startcount
      = (page + 5) > allpage ? allpage - 9 : page - 4;//中間頁起始序號
                 
      //中間頁終止序號
                  endcount = page < 5 ? 10 : page + 5;
                 
      if (startcount < 1) { startcount = 1; } //為了避免輸出的時候產生負數,設置如果小于1就從序號1開始
                  if (allpage < endcount) { endcount = allpage; }//頁碼+5的可能性就會產生最終輸出序號大于總頁碼,那么就要將其控制在頁碼數之內
                  pagestr = "" + allpage + "頁&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

                      pagestr
      += page > 1 ? "<a href=\"" + query_string + "?page=1\">首頁</a>&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + pre + "\">上一頁</a>" : "<B>首頁 上一頁</B>";
                     
      //中間頁處理,這個增加時間復雜度,減小空間復雜度
                      for (int i = startcount; i <= endcount; i++)
                      {
                          pagestr
      += page == i ? "&nbsp;&nbsp;<B>" + i + "<B>" : "&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + i + "\">" + i + "</a>";
                      }
                      pagestr
      += page != allpage ? "&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + next + "\">下一頁</a>&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + allpage + "\">末頁</a>" : " 下一頁 末頁";

                 
      return pagestr;
              }
              


      來源:csdn

      分享:aspx頁面彈出窗口代碼大全
      //關閉,父窗口彈出對話框,子窗口直接關閉 this.Response.Write(scriptlanguage=javascriptwindow.close();/script); //關閉,父窗口和子窗口都不彈出對話框,直接關閉 this.Response.Write(script); this.Response.Write({top.opener=null;top.close();}

      來源:模板無憂//所屬分類:.Net教程/更新時間:2012-06-18
      相關.Net教程