在asp.net中長內容自動分頁的實現-.NET教程

來源:互聯網
上載者:User
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class Page : System.Web.UI.Page
13 {
14     private string str;//字元
15     private int strl;//字元總長度
16     private int pagesize;//每頁顯示的字元數
17     protected void Page_Load(object sender, EventArgs e)
18     {
19         // 在此處放置使用者代碼以初始化頁面  
20         str = "1234567891234567898522555";
21         pagesize = 3;
22         strl = str.Length;
23         Response.Write(strl);
24         substr();
25     }
26
27     private void substr()
28     {
29         int ct = Int32.Parse(Request.QueryString["page"]);
30         if (strl == (strl / pagesize) * pagesize)//看看頁面的總記錄是否能被每頁的記錄數整除
31         {
32             for (int i = 1; i <= strl / pagesize; i++)
33             {
34                 Response.Write("頁:<a href="page.aspx?page=" mce_href="page.aspx?page="" + i + ">" + (i) + "</" + "a>");
35             }
36             string s = str.Substring(pagesize * ct - pagesize, pagesize);
37             Response.Write(s);
38         }
39         else if (ct * pagesize > strl)//在不被整除的情況下,最後一頁的設定,如字元長13,每頁3,則處理最後那一頁的顯示
40         {
41             for (int i = 1; i <= (strl / pagesize) + 1; i++)
42             {
43                 Response.Write("頁:<a href="page.aspx?page=" mce_href="page.aspx?page="" + i + ">" + (i) + "</" + "a>");
44             }
45             string s = str.Substring((ct - 1) * pagesize, strl - (ct - 1) * pagesize);
46             Response.Write(s);
47         }
48         else   //在不被整除的情況下其他頁面的顯示設定
49         {
50             for (int i = 1; i <= strl / pagesize + 1; i++)
51             {
52                 Response.Write("頁:<a href="page.aspx?page=" mce_href="page.aspx?page="" + i + ">" + (i) + "</" + "a>");
53             }
54             string s = str.Substring(pagesize * ct - pagesize, pagesize);
55             Response.Write(s);
56         }
57     }
58 }

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/duanxifeng888/archive/2010/08/22/5830468.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.