zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    可以使用多少列创建索引?
    如何显示前 50 行?
    简单描述 MySQL 中,索引,主键,唯一索引,联合索引的区别,对数据库的性能有什么影响-从读写两方面?
    实践中如何优化 MySQL ?
    列的字符串类型可以是什么?
    MySQL 里记录货币用什么字段类型好 ?
    什么是通用 SQL 函数?
    对于关系型数据库而言,索引是相当重要的概念?
    为表中得字段选择合适得数据类型?
    SQL 注入漏洞产生的原因?如何防止?
  • 原文地址:https://www.cnblogs.com/xiaoli9627/p/6348028.html
Copyright © 2011-2022 走看看