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

Printing a GridView with Paging

Rate me:
Please Sign up or sign in to vote.
4.74/5 (29 votes)
18 Oct 2007CPOL2 min read 169K   6.4K   86  
This is a WebControl that provides an easy way to prepare an ASP.NET GridView to be paged and printed in the browser.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Shared.WebControls" Namespace="Shared.WebControls" TagPrefix="wc" %>
<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <wc:ReportGridView runat="server" BorderWidth="1" ID="gvSample" AutoGenerateColumns="false" PrintPageSize="23" AllowPrintPaging="true" 
                Width="600px">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Customer Name" />
                <asp:BoundField DataField="PhoneNumber" HeaderText="Customer Phone" ItemStyle-HorizontalAlign="center" />                
            </Columns>            
            <PageHeaderTemplate>
                <br />
                PAGE HEADER TEMPLATE HERE
                <br />
            </PageHeaderTemplate>
            <PageFooterTemplate>
                <br />
                
                <hr />
                Page <%# gvSample.CurrentPrintPage.ToString() %> / <%# gvSample.PrintPageCount %>
                
            </PageFooterTemplate>
        </wc:ReportGridView>
    </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) Intelligent Coder
Canada Canada
I've been developing .NET enterprise applications since 2000.

I am originally from Rio de Janeiro and I am currently working at http://www.intelligentcoder.com in Ontario.

I also have my own startup where we offer client intake forms.

Comments and Discussions