Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
consuming an asmx web service in winforms application 3 37
in Dot net,lastest version of MVC 3 23
SQL Help 27 41
C# Gridview 1 29
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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