码迷,mamicode.com
首页 > 其他好文 > 详细

分页功能的实现

时间:2014-07-19 12:22:09      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   使用   

  使用repeter控件来实现功能。

  功能查看:

bubuko.com,布布扣

  前台代码的是实现如下:

bubuko.com,布布扣
 1         <asp:Repeater ID="Repeater1" runat="server">
 2             <HeaderTemplate>
 3                 <table class="frmtable">
 4                     <tr onmouseover="this.style.backgroundColor=‘#FF0000‘"  onmouseout ="this.style.backgroundColor=‘white‘" >
 5                         <td>编号</td>
 6                         <td>用户名</td>
 7                         <td>年龄</td>
 8                         <td>班级</td>
 9                         <td>登记时间</td>
10                         <td>操作</td>
11                     </tr>
12                 </table>
13             </HeaderTemplate>
14             <ItemTemplate>
15                 <table class="frmtable">
16                     <tr onmouseover="this.style.backgroundColor=‘#FF0000‘"  onmouseout ="this.style.backgroundColor=‘white‘" >
17                         <td><%#Eval("id") %></td>
18                         <td><%#Eval("username") %></td>
19                         <td><%#Eval("age") %></td>
20                         <td><%#Eval("class") %></td>
21                         <td>
22                             <%#ToDateTime(Eval("time")) %>
23                         </td>
24                         <td>
25                             <a href="javascript:confirmDelete(‘delete.aspx?deleteid=<%#Eval("id") %>‘)"><%#Eval("handle") %></a> 
26                         </td>                        
27                     </tr>
28                 </table>
29             </ItemTemplate>
30         </asp:Repeater>
31 
32         <div>
33             <%=PageText %>
34         </div>
35         <img alt ="第一张" id="imgs" src="image/1.jpg" style="z-index: 1; left: 1030px; top: 91px; position: absolute; height: 300px; width: 300px" />
Repeter前台实现代码

  后台代码如下:

bubuko.com,布布扣
 1     protected string PageText = "";
 2     protected void Page_Load(object sender, EventArgs e)
 3     {
 4         MySqlConnection myconn = DBhelper.GetConnection();
 5         //PageText += "asd";
 6         setPageList();
 7         myconn.Close();
 8     }
 9     /// <summary>
10     /// 分页显示表格代码
11     /// </summary>
12     public void setPageList()
13     {
14         double pageConfig = 10; //每页多少条
15         double infoCount = 0; //共有多少条记录
16         //读取数据库中的记录
17         MySqlConnection conn = DBhelper.GetConnection();
18         MySqlCommand cmd = new MySqlCommand("select count(*) from login", conn);//求有多少条记录
19         infoCount = Convert.ToInt16(cmd.ExecuteScalar());
20         double lastly = infoCount / pageConfig;// 求分页数,共有多少页
21         int page = Convert.ToInt16(Request.QueryString["page"]);// 当前第几页
22         if (page == 0)
23         {
24             page = 1;
25         }
26         //int first = 1;
27         int last = page - 1;// 上一页
28         int nextpage = page + 1;// 下一页 做翻页用
29         if (lastly == 1)
30         { }
31         else
32         {
33             if (Convert.ToInt16(lastly.ToString().Split(.).Length) != 1)
34             {
35                 lastly = Convert.ToInt16(lastly.ToString().Split(.)[0]) + 1; //分页数如果不是整数那么加1
36             }
37         }
38         string sql = "";
39         if (page == 1)
40         {
41             sql = "select * from login limit 0,10";
42         }
43         else
44         {
45             sql = "select * from login limit " + (page - 1) * 10 + ",10 ";
46         }
47         MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
48         DataSet ds = new DataSet();
49         da.Fill(ds);
50         this.Repeater1.DataSource = ds;
51         this.Repeater1.DataBind();
52         if (page > 1)
53         {
54             PageText += "<a href=\"?page=" + (page > 1 ? page - 1 : 1) + "\">上一页</a>";
55         }
56         for (int i = 1; i <= lastly; i++)
57         {
58             if (page == i)
59             {
60                 PageText += "<b>[" + i.ToString() + "]</b>";
61             }
62             else
63             {
64                 PageText += "<a href=‘?page=" + i.ToString() + "‘>" + i.ToString() + "></a>";
65             }
66         }
67         if (page < lastly)
68         {
69             PageText += "<a href=\"?page=" + (page >= lastly ? lastly : page + 1) + "\">下一页</a>";
70         }
71     }
Repeter后台实现代码

分页功能的实现,布布扣,bubuko.com

分页功能的实现

标签:style   blog   http   java   color   使用   

原文地址:http://www.cnblogs.com/zyxdbk/p/3854650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!