Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 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 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 1st, 2007, 04:07 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in exporting data from datagrid to Excel

Hi
   All,

   facing a problem in exporting datagrid to excel.I need some specific column of the grid(not the whole grid)to be exported to excel.have been able to export the whole grid with the following code

Response.Clear();
            Response.Buffer= true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.Charset = "";
            this.EnableViewState = false;
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            this.ClearControls(DataGrid1);
            DataGrid1.RenderControl(oHtmlTextWriter);
            Response.Write(oStringWriter.ToString());
            Response.End();

So, can anybody tell what should i do?

  #2 (permalink)  
Old August 1st, 2007, 06:40 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: Amman, , Jordan.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i don't know if that will help, but y don't you bind the column you need to the datagrid and then export it.




Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
  #3 (permalink)  
Old August 1st, 2007, 07:54 AM
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

Set all the columns you don't wish to see to Visible=false before you render the control. Then only the column you want to see will show up.

-Peter
  #4 (permalink)  
Old August 3rd, 2007, 06:30 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks
  planoie,

         Your trick works great!!But it only works with the bounded columns only,not been able to work with the autogenerated columns.
Please let me know the solution.

  #5 (permalink)  
Old August 4th, 2007, 09:21 AM
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

If you know what columns you don't want to show, then presumably you know what columns you DO want to show, so add the desired columns to the columns collection and turn off autogeneratecolumns.

-Peter
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data from datagrid to excel??? twyce C# 3 March 4th, 2010 04:51 AM
problem in exporting datagrid to excel swati_joshi ASP.NET 1.0 and 1.1 Professional 3 June 4th, 2006 11:26 PM
Exporting data to excel from datagrid, Problem. swadhinm ASP.NET 1.x and 2.0 Application Design 0 May 31st, 2005 01:44 AM
problem exporting datagrid to excel kscdave Classic ASP Professional 0 March 29th, 2005 11:57 AM
Exporting DataGrid To Excel chiefg C# 2 December 31st, 2003 12:23 PM



All times are GMT -4. The time now is 09:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.