Introduction
- Here, I will explain how to use custom pagination in GridView with formatting, using ASP.NET.
- Follow the steps mentioned below to achieve our requirement.
Step 1
Follow the code, mentioned below, to achieve the result Default.aspx.
- <asp:GridView ID="CustomGrid" runat="server" EnableModelValidation="True" AutoGenerateColumns="False" AllowPaging="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4″ ForeColor=" Black " GridLines="Vertical "
- EmptyDataText="No record found. " PageSize="2″>
- <AlternatingRowStyle BackColor="White" />
- <Columns>
- <asp:TemplateField HeaderText="UserID">
- <ItemTemplate>
- <asp:Label ID="lblUser" runat="server" Text=’<%# Eval( "ID") %>’></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundField DataField="NAME" HeaderText="Name">
- </asp:BoundField>
- <asp:BoundField DataField="PRICE" HeaderText="Price">
- </asp:BoundField>
- </Columns>
- <FooterStyle BackColor="#CCCC99″ />
- <HeaderStyle BackColor=" #6B696B " Font-Bold="True " ForeColor="White " />
- <PagerSettings FirstPageText="First " LastPageText="Last " NextPageText="Next " Position="TopAndBottom "
- PreviousPageText="Prev " />
- <PagerStyle BackColor="#F7F7DE " ForeColor="Black " HorizontalAlign="Right " />
- <PagerTemplate>
- <div>
- <span style="float: right; ">
- <asp:ImageButton ID="ImageButtonNext " runat="server " ImageUrl="~/images/r-arrow.png "
- OnClick="ImageButtonNext_Click " />
- </span><span style="float: right; padding-left: 5px; padding-right: 5px; ">
- <asp:Label ID="LabelCurrentIndex " runat="server " Text=’<%= CurrentSelectedIndex %>’></asp:Label>
- Of
- <asp:Label ID="LabelLastIndex " runat="server " Text=’<%= TotalPageCount %>’></asp:Label>
- </span><span style="float: right; ">
- <asp:ImageButton ID="ImageButtonPrev " runat="server " ImageUrl="~/images/l-arrow.png "
- OnClick="ImageButtonPrev_Click " />
- </span>
- </div>
- </PagerTemplate>
- <RowStyle BackColor="#F7F7DE " />
- <SelectedRowStyle BackColor="#CE5D5A " Font-Bold="True " ForeColor="White " />
- </asp:GridView>
- <input type="hidden " id="GridActiveIndex " value="0″ runat="server" />
Step 2
Add the code, mentioned below, to Default.aspx.cs.
Add the code, mentioned below, to Default.aspx.cs.


Join the conversation! Your thoughts help the community grow.