使用asp.net对下一页,上一页按钮和显示页面总页数进行分页

时间:2016-05-11 13:02:40

标签: c# asp.net gridview

我已经在网格视图中完成了所有工作。还有一个要求。接下来,使用asp.net的前一页按钮和显示总页数的页码Ex:我需要显示同一行的第4页。实际上我已经编写了代码,显示第4页,共10页代码.aspx.cs低于  protected void gvformlist_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Pager) { e.Row.Cells[0].Text = "Page " + (gvformlist.PageIndex + 1) + " of " + gvformlist.PageCount; } }但它只显示页码和总页数,但在同一个寻呼机中,我需要按钮和页码,如第3页,共10页。我该怎么办? .aspx的代码低于

 <asp:GridView ID="gvformlist" runat="server" ShowHeaderWhenEmpty="true" EmptyDataText="No results match the specified search criteria"
                OnRowDataBound="gvformlist_RowDataBound" PagerSettings-Position="Top" AllowPaging="true" ShowHeader="true" AutoGenerateColumns="false" Width="100%" AllowSorting="true" CssClass="gv" OnPageIndexChanging="gvformlist_PageIndexChanging">
                <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First " NextPageText="Next " PreviousPageText="Previous " LastPageText="Last " />
                <PagerStyle CssClass="cssPager" />

1 个答案:

答案 0 :(得分:2)

尝试将ShowFooter="true"添加到gridview。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Footer)
    {
       e.Row.Cells[0].Text = "Page " + (GridView1.PageIndex + 1) + " of " + GridView1.PageCount;
    }
}