开发者

Insert custom information into GridView Pager possible?

开发者 https://www.devze.com 2022-12-22 09:36 出处:网络
Is it possible to insert information into the gridview\'s pager, like \"Showing 10 of 55 items (You are on page 3)\" and bind that infor开发者_运维知识库mation accordingly to the actual PageCount and

Is it possible to insert information into the gridview's pager, like "Showing 10 of 55 items (You are on page 3)" and bind that infor开发者_运维知识库mation accordingly to the actual PageCount and PageSize properties?

I can only think of doing it outside the pager, even outside the GridView.


You can use the PagerTempate-property:

<asp:GridView Id="MyGridView" runat="server" AllowPaging="true">

<PagerTemplate>

      <asp:LinkButton CommandName="Page" CommandArgument="First" ID="lbFirst" runat="server">First</asp:LinkButton>

      <asp:LinkButton CommandName="Page" CommandArgument="Prev" ID="lbPrev" runat="server">&lt;</asp:LinkButton>

      [Items <%= MyGridView.PageIndex * MyGridView.PageSize %> - <%= MyGridView.PageIndex * MyGridView.PageSize + MyGridView.PageSize - 1 %>]

      <asp:LinkButton CommandName="Page" CommandArgument="Next" ID="lbNext" runat="server">&gt;</asp:LinkButton>

      <asp:LinkButton CommandName="Page" CommandArgument="Last" ID="lbLast" runat="server">&gt;&gt;</asp:LinkButton>          

</PagerTemplate>

...


You can also make your custom Griview which inherites from the standard Griview. Then you can override the InitializePager-method:

protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
    {

            TableCell pagerCell = new TableCell();
            pagerCell.ColumnSpan = columnSpan;

            LinkButton linkFirst = new LinkButton();
            linkFirst.ToolTip = "Go to first page";
            linkFirst.CommandName = "Page";
            linkFirst.CommandArgument = "First";

            pagerCell.Controls.Add(linkFirst);

            row.Cells.Add(pagerCell);
    }

I've just pasted some bits of my code together here, so I don't know if this code snippet works but it should give you a good indication of how you can override the InitializePager-method! :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号