How to print the contents of a GridView

Hi Experts,

I have a ASP.net web application with C# as the code behind language which pulls data from a DB table and displays it in a GridView.
The data is pretty large and  runs to around 50 pages when paging is allowed in the GridView. It makes to sense to print each page by using the browser's print functionality.
How do I write a customized print function which prints all the GridView's records ?

Thanks.
fantasylanAsked:
Who is Participating?
 
krys2ferConnect With a Mentor Commented:
You can create a new page with the GridView minus the paging alone and pop it during printing.
0
 
MikeMCSDCommented:
You can get really good control of printing by using CSS.
0
 
russellCCommented:
Have you tried something like this?
using System.Drawing.Printing;

protected void Button1_Click()
    {
        PrintDocument pd = new PrintDocument();

        foreach(Page page in GridView1.Page)
        {
            pd.Print(page);
        }
    }

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Kumaraswamy RCommented:
Hi

Bellow url Give some information

how to print data in a DataGridView, please visit the following links:

http://www.codeproject.com/KB/printing/datagridviewprinter.aspx
http://www.codeproject.com/KB/printing/DGVPrinter.aspx
0
 
apexpertCommented:
Hi Dear..

Please add this button on html
<asp:Button CssClass="button" ID="btnPrnt" runat="server" Text="Print Preview" />

Add in aspx.cs Page on page load
btnPrnt.Attributes.Add("Onclick", "getPrint('print');")

Do more thing add a one more grid with full record and visible =false
 then
<div id="print">
Your grid here
</div>

0
 
fantasylanAuthor Commented:
Hi apexexpert,

I tried what you mentioned but I am printing just a blank page. I also made the GridVew visible to make sure that there was data in it.

Any ideas on what I might be doing wrong ?

Regards.
0
 
fantasylanAuthor Commented:
Hi russellC,

The code you posted didnt work for me as I got an Ienumerable error.

Regards.
0
 
fantasylanAuthor Commented:
Hi rkworlds,

I am looking to print a GridView and not a DataGridView. I am not sure the tutorials that you pointed out would work as they are customized to windows forms rather than web forms.

Regards.
0
 
apexpertCommented:
please check  your enableviewstate="true" for gridview

sometimes it happens due to visible false so you can try one more thing just check your view source have it contains the data or grid view.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.