Solved

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

Posted on 2004-04-08
4
300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
MVC5 Dataformat String for Phone not working 3 25
Problem to error 4 44
Capture logon name 13 31
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now