Insert custom information into GridView Pager possible?
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"><</asp:LinkButton>
[Items <%= MyGridView.PageIndex * MyGridView.PageSize %> - <%= MyGridView.PageIndex * MyGridView.PageSize + MyGridView.PageSize - 1 %>]
<asp:LinkButton CommandName="Page" CommandArgument="Next" ID="lbNext" runat="server">></asp:LinkButton>
<asp:LinkButton CommandName="Page" CommandArgument="Last" ID="lbLast" runat="server">>></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! :-)
精彩评论