Sujinig
asked on
Export to excel data from datagrids in asp.net that has stylesheet.
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.HtmlTextWrit er htmltextwriter = new HtmlTextWriter (stringwriter);
dgMoneyContributions.GridL ines = GridLines.None ;
dgProductContributions.Gri dLines = GridLines.None ;
dgStockContributions.GridL ines = GridLines.None ;
dgThriftContributions.Grid Lines = GridLines.None ;
dgInKindContributions.Grid Lines = GridLines.None ;
BindData (); // set of functions that bind data to the datagrids
dgMoneyContributions.Rende rControl(h tmltextwri ter);
dgProductContributions.Ren derControl (htmltextw riter);
dgStockContributions.Rende rControl(h tmltextwri ter);
dgThriftContributions.Rend erControl( htmltextwr iter);
ggInKindContributions.Rend erControl( htmltextwr iter);
Response.Write (stringwriter.ToString ());
Response.End() ;
when i test i get the exception
System.Web.HttpException: Control 'dgMoneyContributions__ctl 1__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
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.HtmlTextWrit
dgMoneyContributions.GridL
dgProductContributions.Gri
dgStockContributions.GridL
dgThriftContributions.Grid
dgInKindContributions.Grid
BindData (); // set of functions that bind data to the datagrids
dgMoneyContributions.Rende
dgProductContributions.Ren
dgStockContributions.Rende
dgThriftContributions.Rend
ggInKindContributions.Rend
Response.Write (stringwriter.ToString ());
Response.End() ;
when i test i get the exception
System.Web.HttpException: Control 'dgMoneyContributions__ctl
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
ASKER
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!
Thanks Anyway!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check out this article
http://www.dotnetjohn.com/articles/articleid36.aspx
http://www.dotnetjohn.com/articles/articleid78.aspx