ASP.NET练习③——AspNetChosmePager

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

posted @ 2017-01-24 23:23  AaronLi  阅读(153)  评论(0编辑  收藏  举报