zoukankan      html  css  js  c++  java
  • DbEntry采用分页技术显示数据在GridView里面并用AspNetPager控件来显示分页

    1.后台代码

            protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    RefreshViewer(1);
    }
    }
    private void RefreshViewer(int NewIndex)
    {
    var ps = DbEntry
    .From<User>()
    .Where(Condition.Empty)
    .OrderBy((DESC)"Id")
    .PageSize(20)
    .GetPagedSelector();
    var count = ps.GetResultCount();

    //Aspnetpager1 Properties Setting
    AspNetPager1.RecordCount = Convert.ToInt32(count);
    AspNetPager1.PageSize = 20;
    AspNetPager1.UrlPaging = true;

    NewIndex = NewIndex < 1 ? 1 : NewIndex;
    //GridView Properties Setting
    this.GridView1.PageSize = 20;
    GridView1.DataKeyNames = new string[] { "Id"};
    GridView1.PageIndex = NewIndex;
    GridView1.DataSource = ps.GetCurrentPage(NewIndex-1);
    GridView1.DataBind();
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
    RefreshViewer(e.NewPageIndex);
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    //Add Confirm messaged
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
    {
    ((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick",
    "javascript:return confirm('你确认要删除:"+ e.Row.Cells[1].Text + "吗?')");
    }
    }
    //Change Rows Mouceover and Mouceout Color
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
    }
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    string id = GridView1.DataKeys[e.RowIndex].Value.ToString()+"";
    User o = User.FindById(1);
    o.Delete();

    }

      前台代码:

      <div>
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
    ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound"
    OnRowDeleting="GridView1_RowDeleting">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
    <asp:BoundField DataField="Id" FooterText="Id" HeaderText="Id" />
    <asp:BoundField DataField="Name" HeaderText="Name" />
    <asp:CommandField ShowDeleteButton="True" />
    </Columns>
    <EditRowStyle BackColor="#999999" />
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#E9E7E2" />
    <SortedAscendingHeaderStyle BackColor="#506C8C" />
    <SortedDescendingCellStyle BackColor="#FFFDF8" />
    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>
    <br />
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="第一页" LastPageText="最后一页"
    NextPageText="下一页" PrevPageText="上一页" Font-Names="Arial" AlwaysShow="true" ShowInputBox="Never"
    CssClass="pages" CurrentPageButtonClass="cpb" UrlPaging="True" OnPageChanging="AspNetPager1_PageChanging"
    HorizontalAlign="Center" PageSize="30">
    </webdiyer:AspNetPager>
    </div>



  • 相关阅读:
    #Git 21天打卡第一天 01天0526
    老徐第六期百人计划之职业发展方向&学习方向
    LR12.53安装中文补丁包,录制后回放脚本一致卡在编译的问题
    常用oracle语句整理
    LoadRunner11之批量插入SQL数据~2
    LoadRunner12之SQLServer数据库批量插入--.Net协议
    Jmeter连接Oracle数据库简单使用
    AppScan安装使用
    SQL多表连接
    [剑指Offer] 4.二维数组的查找
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2332362.html
Copyright © 2011-2022 走看看