p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Problem in exporting data from datagrid to Excel (http://p2p.wrox.com/showthread.php?t=60710)

deb_kareng August 1st, 2007 04:07 AM

Problem in exporting data from datagrid to Excel

   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.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);

So, can anybody tell what should i do?

zaghmout August 1st, 2007 06:40 AM

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"

planoie August 1st, 2007 07:54 AM

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.


deb_kareng August 3rd, 2007 06:30 AM


         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.

planoie August 4th, 2007 09:21 AM

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.


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

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