Solved

Export to excel data from datagrids in asp.net that has stylesheet.

Posted on 2004-04-08
4
299 Views
Last Modified: 2012-06-27
I have a asp.net page where when user selects certain filters, i show them the result data in multiple datagrids. I need to export these data to a excel sheet when they click a button.

the code i used is as follows
 
                                                Response.Clear ();
                  Response.Charset = "";
                  Response.ContentType = "application/vnd.ms-excel";
                  
                  System.IO.StringWriter stringwriter = new System.IO.StringWriter ();
                  System.Web.UI.HtmlTextWriter htmltextwriter = new HtmlTextWriter (stringwriter);

                  
                  dgMoneyContributions.GridLines = GridLines.None ;
                  dgProductContributions.GridLines = GridLines.None ;
                  dgStockContributions.GridLines = GridLines.None ;
                  dgThriftContributions.GridLines = GridLines.None ;
                  dgInKindContributions.GridLines = GridLines.None ;

                  BindData (); // set of functions that bind data to the datagrids

                  dgMoneyContributions.RenderControl(htmltextwriter);
                  dgProductContributions.RenderControl(htmltextwriter);
                  dgStockContributions.RenderControl(htmltextwriter);
                  dgThriftContributions.RenderControl(htmltextwriter);
                  ggInKindContributions.RenderControl(htmltextwriter);

                  Response.Write (stringwriter.ToString ());
                  Response.End() ;

when i test i get the exception

System.Web.HttpException: Control 'dgMoneyContributions__ctl1__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.

My Page contains stylesheet references and the datagrids themselves contain a hyperlink column. Is this causing the error, if so how to proceed with the export function?

Thanks in advance

0
Comment
Question by:Sujinig
4 Comments
 
LVL 1

Expert Comment

by:nparthi
ID: 10834624
The excel shoudl import the column even if it is a hyperlink.
Check out this article

http://www.dotnetjohn.com/articles/articleid36.aspx

http://www.dotnetjohn.com/articles/articleid78.aspx
0
 

Author Comment

by:Sujinig
ID: 10860197
I figured why there was an error, it was due to Paging and Sorting. Once I removed the Paging and Sorting it works Fine.

Thanks Anyway!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11121766
PAQed, with points refunded (250)

Computer101
E-E Admin
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now