• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1696
  • Last Modified:

ASP:GridView Custom PagerTemplate

Hi All,

I wish to create a custom pager for my gridview. I have the First, Previous, Next and Last asp:Button working, but I want a page count in the middle of the buttons.

Can someone help please. :)

Marc
<PagerTemplate>
                    <asp:Button CommandName="Page" CommandArgument="First" ID="FirstButton" runat="server" CssClass="GridViewPagerButtonFirst" ToolTip="First Page" />
                    <asp:Button CommandName="Page" CommandArgument="Prev" ID="PrevButton" runat="server" CssClass="GridViewPagerButtonPrev" ToolTip="Previous Page" />
                    <asp:Button CommandName="Page" CommandArgument="Next" ID="NextButton" runat="server" CssClass="GridViewPagerButtonNext" ToolTip="Next Page" />
                    <asp:Button CommandName="Page" CommandArgument="Last" ID="LastButton" runat="server" CssClass="GridViewPagerButtonLast" ToolTip="Last Page" />
                </PagerTemplate>

Open in new window

0
marc_butler
Asked:
marc_butler
  • 2
2 Solutions
 
informaniacCommented:
<PagerTemplate>
        <asp:Button CommandName="Page" CommandArgument="First" ID="FirstButton" runat="server" CssClass="GridViewPagerButtonFirst" ToolTip="First Page" />
        <asp:Button CommandName="Page" CommandArgument="Prev" ID="PrevButton" runat="server" CssClass="GridViewPagerButtonPrev" ToolTip="Previous Page" />
        <asp:Label ID="lblPageCount" runat="server"></asp:Label>
        <asp:Button CommandName="Page" CommandArgument="Next" ID="NextButton" runat="server" CssClass="GridViewPagerButtonNext" ToolTip="Next Page" />
        <asp:Button CommandName="Page" CommandArgument="Last" ID="LastButton" runat="server" CssClass="GridViewPagerButtonLast" ToolTip="Last Page" />
    </PagerTemplate>

Open in new window


protected void gv1_DataBound(object sender, EventArgs e)
        {
            GridViewRow pagerRow = gv1.BottomPagerRow;
            Label lblPageCount = pagerRow.Cells[0].FindControl("lblPageCount") as Label;

            lblPageCount.Text = gv1.PageCount.ToString();
        }

Open in new window

0
 
marc_butlerAuthor Commented:
Hi Informaniac,

Sorry I did explain my request very well. I was looking for a click-able list of page numbers i.e.

1 2 3 4 5

Im also programming in VB, so attached is my version of your above code.
    Private Sub GV_CLAIMSELECT_DataBound(sender As Object, e As System.EventArgs) Handles GV_CLAIMSELECT.DataBound

        Dim pagerRow As GridViewRow = GV_CLAIMSELECT.BottomPagerRow
        Dim lblPageCount As Label = DirectCast(pagerRow.Cells(0).FindControl("lblPageCount"), Label)
        lblPageCount.Text = GV_CLAIMSELECT.PageCount.ToString()

    End Sub

Open in new window

0
 
informaniacCommented:
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now