Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

Export Gridview to Excel, too much info

I am using the following code to export a gridview into Excel:

                Response.Clear();
                Response.AddHeader("content-disposition", "attachment;filename=Alldata.xls");
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/vnd.ms-excel";
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                GridView1.RenderControl(htmlWrite);
                Response.Write(stringWrite.ToString());
                Response.End();

On the same form that the gridview control is in there is also a couple of  dropdown list with various information.  Well when I use the above code to export the Gridview I get all the values from the dropdowns to appear on the spreadsheet too.  How do I make it so only the information from the gridview appears in the Excel spreadsheet and nothing else? Thanks.
0
tonyedmo
Asked:
tonyedmo
1 Solution
 
SystemExpertCommented:


Hi,

You can use SQL REPORTING SERVICES for export to excel,PDF ,..... and you can also  

or

private void ExportLinkButton_Click(object sender, System.EventArgs e)
{
  string strTitle = “put the grid title here”;
  new DataGridExcelExporter(this.YourGridName , this.Page).Export(strTitle);
}
where,

strTitle is the title of the DataGrid.
DataGridExcelExporter is the name of main class.
this.YourGridName is the DataGrid object.
this.Page is the current Page object.


or

 you can go for this link and find the solution

http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp

http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx

Thanks
 
0
 
tonyedmoAuthor Commented:
Thanks for your help, but all these examples still don't solve my problem.  For some reason with all these examples its throwing all the information from my dropdown lists along with my gridview into an Excel Spreadsheet.  I just want the information from my gridview in the spreadsheet.  Does anybody know what is going on with that?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now