Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to print the contents of a GridView

Posted on 2010-01-05
9
Medium Priority
?
789 Views
Last Modified: 2012-05-08
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.
0
Comment
Question by:fantasylan
9 Comments
 
LVL 16

Expert Comment

by:MikeMCSD
ID: 26187011
You can get really good control of printing by using CSS.
0
 
LVL 4

Accepted Solution

by:
krys2fer earned 2000 total points
ID: 26187166
You can create a new page with the GridView minus the paging alone and pop it during printing.
0
 
LVL 3

Expert Comment

by:russellC
ID: 26187227
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 26187413
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
 
LVL 4

Expert Comment

by:apexpert
ID: 26188062
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
 

Author Comment

by:fantasylan
ID: 26191092
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
 

Author Comment

by:fantasylan
ID: 26191117
Hi russellC,

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

Regards.
0
 

Author Comment

by:fantasylan
ID: 26191140
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
 
LVL 4

Expert Comment

by:apexpert
ID: 26196765
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question