Click here to Skip to main content
15,897,291 members
Articles / Web Development / ASP.NET

Gridview with SQL Paging

Rate me:
Please Sign up or sign in to vote.
3.00/5 (4 votes)
21 Jul 2009CPOL2 min read 24K   252   25  
A simple and detailed ASP.NET program using Gridview with paging in SQL 2005
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs" Inherits="home" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Tom Bauto - Sample Gridview Binding with Paging from SQL 2005</title>
    <style type="text/css">
        body
        {
        	font-family:Verdana;
        	font-size:10px;
        	font-weight:normal;
        }
        .numtxt
        {
        	font-family:Verdana;
        	font-size:10px;
        	font-weight:normal;
        	width:30px;
        	height:12px;
        	text-align:center;
        }
        .dtxt
        {
        	font-family:Verdana;
        	font-size:10px;
        	font-weight:normal;
        	width:50px;
        	height:18px;
        	text-align:left;
        }
        .btn
        {
        	font-family:Verdana;
        	font-size:10px;
        	font-weight:normal;
        	height:20px;
        	width:60px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Both" Width="1000px" AutoGenerateColumns="false">
            <RowStyle BackColor="White" ForeColor="#333333" />
            <FooterStyle BackColor="White" ForeColor="#333333" />
            <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#DCE7F0" />
            <RowStyle Height="20px" />
            
            <Columns>
                <asp:BoundField DataField="ProductId" HeaderText="Id"><ItemStyle Width="100px" /></asp:BoundField>
                <asp:BoundField DataField="CompanyName" HeaderText="Company"><ItemStyle Width="350px" /></asp:BoundField>
                <asp:BoundField DataField="ProductName" HeaderText="Product"><ItemStyle Width="250px" /></asp:BoundField>
                <asp:BoundField DataField="UnitPrice" HeaderText="Price"><ItemStyle Width="200px" /></asp:BoundField>
                <asp:BoundField DataField="UnitsInStock" HeaderText="Units"><ItemStyle Width="100px" /></asp:BoundField>
            </Columns>
            
        </asp:GridView>
        <div style="width:900px; text-align:left;">
            <table>
                <tr>
                    <td style="height:30px;">
                        <div id="div_total_records" runat="server"></div>
                    </td>
                    <td style="height:30px;">
                        Rows per result:&nbsp;<asp:TextBox ID="txtTotalRowsPerPage" runat="server" CssClass="numtxt"></asp:TextBox>&nbsp;
                    </td>
                    <td valign="middle">
                        Jump:&nbsp;<asp:TextBox ID="txtPage" runat="server" CssClass="numtxt"></asp:TextBox>&nbsp;
                    </td>
                    <td valign="middle">
                        <asp:Button ID="btnJump" runat="server" Text="Jump" CssClass="btn" />
                    </td>
                    <td valign="middle">
                        <asp:DropDownList ID="txtJumpToPage" runat="server" AutoPostBack="true" CssClass="dtxt"></asp:DropDownList>
                    </td>
                    <td valign="middle">
                        <asp:Button ID="btnPrevious" runat="server" Text="Previous" CssClass="btn" />
                    </td>
                    <td valign="middle">
                        <asp:Button ID="btnNext" runat="server" Text="Next" CssClass="btn" />
                    </td>
                </tr>
            </table>
        </div> 
    
    </div>
    </form>
</body>
</html>

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) RealPage, Inc.
Philippines Philippines
I am very passionate about software development
My daily interest is to contribute on innovations.

Let's collaborate, let me know at tom.bauto@gmail.com

Comments and Discussions