Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old June 16th, 2008, 12:13 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default 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?

  #2 (permalink)  
Old June 16th, 2008, 01:08 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Shut off paging on the control and it will render all the data.

-Peter
compiledthoughts.com
  #3 (permalink)  
Old June 16th, 2008, 01:47 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default

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?

  #4 (permalink)  
Old June 16th, 2008, 02:31 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
  #5 (permalink)  
Old June 16th, 2008, 02:56 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
  #6 (permalink)  
Old June 16th, 2008, 03:02 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
  #7 (permalink)  
Old June 16th, 2008, 04:03 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 62
Thanks: 0
Thanked 1 Time in 1 Post
Default

Good lord, I feel like an idiot...

Thanks Peter, I appreciate it.

  #8 (permalink)  
Old June 17th, 2008, 01:28 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Gridview to Excel and Hide column PDALUX ASP.NET 2.0 Basics 2 March 1st, 2012 02:16 AM
Adding to Export Of GridView to Excel rsearing ASP.NET 2.0 Professional 17 January 25th, 2007 02:41 AM
Export to Excel as .csv file from JSP naheedv Reporting Services 3 November 30th, 2006 08:04 AM
How To Export a specific Excel Sheet as a csv file mrjits Excel VBA 5 August 1st, 2006 03:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.