• Linq+AspNetPager+Gridview的结合使用


    XHTML结构:

    <asp:GridView ID="GridView1" runat="server" CssClass="tbtitle acenter" Width="100%" 
        BackColor="#E2F5BC" BorderWidth="0" CellPadding="1" CellSpacing="1" >
    </asp:GridView>
    <!-- Pagination -->
    <webdiyer:AspNetPager Width="100%" ID="anpager" runat="server"
            FirstPageText="首页 |"
            LastPageText="| 尾页" 
            PrevPageText="上一页 |"
            NextPageText="| 下一页"
            OnPageChanged="anpager_PageChanged" 
            PageIndexBoxType="DropDownList" 
            ShowPageIndexBox="Always" 
            TextAfterPageIndexBox=" 页" TextBeforePageIndexBox="第 "
            NumericButtonCount="10" 
            ShowPageIndex="true" 
            ShowBoxThreshold="10" 
            ShowNavigationToolTip="True" 
            PageSize="12"
            AlwaysShow="true" UrlPaging="false">
    </webdiyer:AspNetPager>
    

    .cs(C#):

    private void BindList()
    {
        List<tbSalesOrderHeader> list = new List<tbSalesOrderHeader>();
        list = BSalesOrderHeader.GetList(anpager.CurrentPageIndex, anpager.PageSize);
        if (list.Count > 0)
        {
            anpager.RecordCount = BSalesOrderHeader.GetCount(); //读取所有符合的记录数
            gvList.DataSource = list;
            gvList.DataBind();
        }
    }
    
    protected void anpager_PageChanged(object sender, EventArgs e)
    {
        BindList();
    }
    

      

    封装的类:

        public class BSalesOrderHeader
        {
            private static SalesOrderHeaderDataContext dc = Linq2SqlInstance.SalesOrderHeader;
    
            public static List<tbSalesOrderHeader> GetList(int iCurrentIndex, int iPageSize)
            {
                return dc.tbSalesOrderHeader.Skip((iCurrentIndex - 1) * iPageSize).Take(iPageSize).ToList<tbSalesOrderHeader>();
            }
    
            public static int GetCount()
            {
                return dc.tbSalesOrderHeader.Count();
            }
        }
    

    其中,关键点是:Skip((AspNetPager.CurrentPageIndex - 1) * AspNetPager.PageSize).Take(AspNetPager.PageSize); 

  • 相关阅读:
    node.js + expres 的安装
    ubuntu文件夹建立软链接方法
    $.ajax()方法所有参数详解;$.get(),$.post(),$.getJSON(),$.ajax()详解
    与 的区别
    ubuntu卸载软件命令,apt-get remove
    php中session机制的详解
    mysql中查询语句中的一个知识点说明
    Git忽略规则及.gitignore规则不生效的解决办法
    Linux中find常见用法示例
    Waiting for table metadata lock
  • 原文地址:https://www.cnblogs.com/cancer_xu/p/2186217.html
Copyright © 2020-2023  润新知