Link to home
Start Free TrialLog in
Avatar of marc_butler
marc_butler

asked on

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

Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

<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

Avatar of marc_butler
marc_butler

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial