Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-08
4
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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