首页 > Web开发 > 详细

ASP.NET练习③——AspNetChosmePager

时间:2017-01-24 23:44:00      阅读:334      评论:0      收藏:0      [点我收藏+]

aspx代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="_ChosmePager.aspx.cs" Inherits="AspNetChosmePager._ChosmePager" %>
<%@ Register Assembly="Reasee.Controls" Namespace="Reasee.Controls.ChosmePager" TagPrefix="cc1" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="content">
        <asp:ListView ID="lvPC" runat="server">
            <LayoutTemplate>
                <table id="table1">
                   <thead>
                       <tr>
                           <th>PCNum</th>
                           <th>NetIP</th>
                       </tr>
                   </thead>
                    <tbody>
                        <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
                    </tbody>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# Eval("PCNum") %></td>
                    <td><%# Eval("NetIP") %></td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
    </div>
    <div id="pager">
        <cc1:ChosmePager runat="server" ID="cPager" AlwaysShow="true" PageSize="6" FirstPageText="首页" LastPageText="尾页" NextPageText=">>" PrevPageText="<<" OnPageChanged="cPager_PageChanged" ShowCustomInfoSection="Left" >

        </cc1:ChosmePager>
    </div>
    </form>
</body>
</html>

  

 

cs代码:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LvDataBind();
            }
        }

        private void LvDataBind()
        {
            int pageIndex = cPager.CurrentPageIndex - 1;    //索引从1开始
            int pageSize = cPager.PageSize;
            DataTable dt = new _PCManager().GetListByPage(pageSize, pageIndex).Tables[0];
            lvPC.DataSource = dt;
            lvPC.DataBind();
            cPager.RecordCount = new _PCManager().GetTotalCount();
            cPager.CustomInfoText = "记录总数:<font color=\"blue\"><b>" + cPager.RecordCount.ToString() + "</b></font>";
            cPager.CustomInfoText += " 总页数:<font color=\"blue\"><b>" + cPager.PageCount.ToString() + "</b></font>";
            cPager.CustomInfoText += " 当前页:<font color=\"red\"><b>" + cPager.CurrentPageIndex.ToString() + "</b></font>";
        }

        protected void cPager_PageChanged(object src, Reasee.Controls.ChosmePager.PageChangedEventArgs e)
        {
            cPager.CurrentPageIndex = e.NewPageIndex;
            LvDataBind();
        }
    }

  SQL:

ALTER proc [dbo].[GetPCInfoByPage]
@pageSize int,
@pageIndex int
as
 
declare @pageCountStart int
set @pageCountStart = @pageSize * @pageIndex
 
declare @pageCountEnd int
set @pageCountEnd = @pageSize * (@pageIndex + 1)
 
select * from (
    select ROW_NUMBER() over (order by ID asc) row,*
    from PCInfo
)t
where t.row>@pageCountStart and t.row<=@pageCountEnd

  

 

http://pan.baidu.com/s/1c1UDzNU

ASP.NET练习③——AspNetChosmePager

原文:http://www.cnblogs.com/xiaoli9627/p/6348028.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!