how to export a user control to excel

Posted by Ragha under ASP.NET on 3/30/2008 | Views : 5490 | Status : [Member] | Replies : 2
i have a .aspx page in which there is a usercontrol which is populated with the data when i select the options
i was exporting the control but iam not able to get the data in the usercontrol instead of the data the entire page is exported along with banner

but if i use the same code to export datagrid or gridview its working fine

why this is not happening with usercontrol

the below code is used to export

protected void btnExport_Click(object sender, EventArgs e)
Response.Buffer = true;
//Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.ContentType = "application/";
Response.Charset = "";
this.EnableViewState = false;
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);


Please if there is any solution try to help

its urgent


Posted by: Jayakumars on: 9/30/2012 [Member] [MVP] Bronze | Points: 25


using findcontrol after use ur logic.

Mark as Answer if its helpful to you
EmailId :

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 3/30/2008 [Member] Starter

You code is looking messy, Why don''t you use Code toolbar while posting the code, that is given by this website.

Instead of exporting the User Control, you should export its contents. Like suppose you are populating GridView into the user control then try to export the gridview not the whole user control.

If you have multiple GridView, try to combine all of them into one StringWriter and export.

Hope this helps.

Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response