 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 16th, 2008, 12:13 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Export ALL records from GridView into Excel or CSV
Hopefully someone can help me here. I am trying to export my gridview records into Excel or CSV. I have found a ton of examples and they are all EXACTLY the same, like this:
http://p2p.wrox.com/topic.asp?TOPIC_...rms=export,csv
HOWEVER, I have a gridview that will have anywhere from 250 to 5000 records and I have to allow paging at 50 records per page. When I use any of these examples it only exports what is visible at the moment, or what is loaded in the gridview. I want to export EVERYTHING that my SqlDataSource queries - can anyone point me in the right direction?
|
|

June 16th, 2008, 01:08 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Shut off paging on the control and it will render all the data.
-Peter
compiledthoughts.com
|
|

June 16th, 2008, 01:47 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Well... I assumed that is all I had to do. Set Allowpaging and Allowsorting to false, run the download script and then set them back to true, but that doesn't work.
I can certainly shut it off completely and everything works fine, but I need only 50 records at a time displaying.
Is there a way to do that?
|
|

June 16th, 2008, 02:31 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Can you elaborate on "that doesn't work"?
I'm suggesting that you turn off paging when you render for export, not all the time.
-Peter
compiledthoughts.com
|
|

June 16th, 2008, 02:56 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I simply mean it doesn't export all of the records - it still exports only the 50 that are displayed in the gridview. Perhaps I am not doing it properly - this is my click event:
Protected Sub img_export_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles img_export.Click
GridView.AllowPaging = False
GridView.AllowSorting = False
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=exported.xls")
Response.Charset = String.Empty
'Response.ContentType = "application/vnd.xls"
Response.ContentType = "application/vnd.ms-excel"
Dim sw As System.IO.StringWriter = New System.IO.StringWriter()
Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw)
GridView.RenderControl(hw)
Response.Write(sw.ToString())
Response.End()
End Sub
|
|

June 16th, 2008, 03:02 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Ah.... sorry, this didn't click before...
You need to rebind after you have turned off paging. Otherwise, you are simply rendering the gridview that was constructed out of viewstate which contains only 1 page of data.
-Peter
compiledthoughts.com
|
|

June 16th, 2008, 04:03 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Good lord, I feel like an idiot...
Thanks Peter, I appreciate it.
|
|

June 17th, 2008, 01:28 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Quote:
quote:Originally posted by kevorkian
I feel like an idiot...
|
Don't. It's easy to miss the obvious sometimes. Especially with ASP.NET.
-Peter
compiledthoughts.com
|
|
 |