Link to home
Start Free TrialLog in
Avatar of Jerry Miller
Jerry MillerFlag for United States of America

asked on

ASP.Net print gridview data

I have the need in a web application to print gridview data that is displaying on the screen. Currently I am adding the gridview as part of a HTML form to open a new page and add other text to the page. For example, I add the current date, grid name, and query parameters so they can see these on the printed page.

This all seems to work when the dataset is small. However when the dataset grows to about 2000 records, the page occasionally times out before loading. Is there a better way to export data to be printed so it doesn't time out?

I am getting the error "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size has been reached."  Unless building the gridview is taking all pooled connections, which I have at 300, it should not be using all of the connections. This is an internal website that currently is very low in use, no more than 2 or 3 concurrent users as we are not completely in production. It has happened in development when I know that I was the only user. I think that the page may be timing out.

Any help will be greatly appreciated.
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Hi,

First of all, don't load all the records at once to the Grid. Use Pagination.

While printing you can print all the records - http://www.aspsnippets.com/articles/print-functionality-in-asp.net-gridview-control.aspx

Hope it helps u...
Avatar of Jerry Miller

ASKER

I am turning off paging to print everything at once. In my RowDataBound event, I am binding a small repeater that contains multiple records for each row. The repeater only has a few records for each one, 1-3, but this seems to be slowing it down drastically.

I used the example in your post, but I think that the nested repeater is killing me. Any suggestions on how to show the data that I am displaying i the repeater?
Hi,

You should be considering nested GridView - http://csharpdotnetfreak.blogspot.com/2012/06/nested-gridview-example-in-aspnet.html

Hope it helps u...
I have tried various approaches to this including the nested gridviews. I am currently still using the repeater nested in the gridview. It works most of the time, but occasionally times out. I am trying to eliminate all time out issues as my users need to run reports for time periods of months, quarters, etc.

I tried caching the gridview datasource but in order to turn off paging, I have to rebind which is where the slowness occurs.
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
roopeshreddy, I am using stored procedures.

Yes on my rebind I am going back to the database. I tried caching the datasource, but in order to turn off paging I had to rebind which I believe is causing my issue. The gridview loads in about 2 seconds with paging on, but sometimes times out with it off for printing.

What I don't understand is that it works fine sometimes. There could be an issue with one of the web servers or one of the database servers, but unless I can point to one of them with an actual error neither of the groups responsible for them will look at it. There are 4 web servers in a load balanced set up and 2 database servers in a clustered environment.
Hi,

Yeah! You have to nail down the issue by looking at the Load balancing servers!
I added some indexes to my SQL tables based on the query optimizer and it solved my issue.
Led me in the right direction.
As another piece to the puzzle for anyone reading this thread.

I had a small repeater that was being data bound via a separate stored procedure and it was slowing the print function. I removed the repeater and added that information as a join in the original stored procedure.

This provides some extra rows instead of having each line with the invoice number and then a repeater for each sub amount. Any invoice that has multiple sub amounts will have additional rows. Which is not a huge problems since now the report runs every time.
Hi,

Since this post is answered, you can start a new thread!
I was only adding more information about the solution to the issue not asking how to fix it. The problem is resolved.