Click here to Skip to main content
11,717,883 members (78,009 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

Paging GridView with ROW_NUMBER()

, 5 Feb 2006 144.5K 4.4K 82
This article explains how to implement custom paging in the GridView web control using the ROW_NUMBER() function of SQL Server 2005
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PagingGridView.aspx.cs" Inherits="PagingGridView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    	<table align="center">				
					<td align="center">
						<table align="center">
								<td vAlign="top">
									<asp:imagebutton id="PageSizeImb" Runat="server" ImageAlign="AbsBottom" ImageUrl="Images\PageSize.gif"
										ToolTip="Set page size" OnClick="PageSizeImb_Click"></asp:imagebutton>&nbsp;&nbsp;
									<asp:textbox id="PageSizeTxt" Runat="server" Columns="2" Text="3" Font-Bold="True"></asp:textbox>&nbsp;
									<asp:imagebutton id="FirstPage" Runat="server" ImageAlign="AbsBottom" ImageUrl="Images/first.gif"
										ToolTip="First" CommandName="First" OnCommand="NavigationLink_Click"></asp:imagebutton>
									<asp:imagebutton id="PreviousPage" Runat="server" ImageAlign="AbsBottom" ImageUrl="Images/previous.gif"
										ToolTip="Previous" CommandName="Prev" OnCommand="NavigationLink_Click"></asp:imagebutton>&nbsp;&nbsp;
									<asp:imagebutton id="GoToPageImb" Runat="server" ImageAlign="AbsBottom" ImageUrl="Images\GoToPage.gif"
										ToolTip="Go to page number" OnClick="GoToPageImb_Click"></asp:imagebutton>&nbsp;
									<asp:textbox id="GoToPageTxt" runat="server" Width="30px" Text="1" Font-Bold="True"></asp:textbox>&nbsp;
									<asp:imagebutton id="NextPage" Runat="server" ImageAlign="AbsBottom" ImageUrl="Images/next.gif" ToolTip="Next"
										CommandName="Next" OnCommand="NavigationLink_Click"></asp:imagebutton>
									<asp:imagebutton id="LastPage" Runat="server" ImageAlign="AbsBottom" ImageUrl="Images/last.gif" ToolTip="Last"
										CommandName="Last" OnCommand="NavigationLink_Click"></asp:imagebutton>&nbsp;&nbsp;
                                    <asp:Label ID="CurrentPage" runat="server" Text="1" Font-Bold="True"></asp:Label>
									<asp:label id="SepLbl" runat="server" Font-Size="X-Small" CssClass="pageLinks" Enabled="False">/</asp:label>
                                    &nbsp;<asp:Label ID="TotalPages" runat="server" Font-Bold="True">1</asp:Label>&nbsp;

           <td align=center>
           <asp:GridView  ID="GridView1" runat="server" AutoGenerateColumns="False" >
                <asp:BoundField DataField="RowNumber" ItemStyle-HorizontalAlign = "Left" HeaderText="RowNumber" />
                <asp:BoundField DataField="Name" ItemStyle-HorizontalAlign= "Left" HeaderText="Name" />
                <asp:BoundField DataField="SalesYTD" ItemStyle-HorizontalAlign = "Left" HeaderText="SalesYTD" />
                <asp:BoundField DataField="PostalCode" ItemStyle-HorizontalAlign = "Left" HeaderText="PostalCode" />
               <HeaderStyle BackColor="BurlyWood" />
               <RowStyle BackColor="Wheat" />
               <AlternatingRowStyle BackColor="LightGray" />

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Canada Canada
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150901.1 | Last Updated 5 Feb 2006
Article Copyright 2006 by Socrate1
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid