Below is the piece of code through which I was exporting data from gridview control to excel sheet. Grid data is getting exported correctly and I need to add filter functionality to excel sheet in the header row for every column in the button click event
itself.
//exporting data to excel document//
GridView gridview1 = new GridView();
gridview1.DataSource = DischargePatientRecordsForRightFilters;
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridview1.AllowPaging = false;
gridview1.DataBind();
gridview1.DataBound+=new EventHandler(gridview1_DataBound);
//Change the Header Row back to white color
gridview1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gridview1.HeaderRow.Cells.Count; i++)
{
gridview1.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
gridview1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
Below links are having demos which are useful. Now I need to add Filter functionality to excel sheet header columns dynamically on button click itself.
If you want to add the filter function to excel sheet it may hard to implement. You can’t use some controls in the excel file. Or you may give your idea clearly.
Munna1026
0 Points
4 Posts
Exporting Data from Grid to Excel
Mar 30, 2012 10:16 AM|LINK
Hi All,
Below is the piece of code through which I was exporting data from gridview control to excel sheet. Grid data is getting exported correctly and I need to add filter functionality to excel sheet in the header row for every column in the button click event itself.
How could I achieve this?
protected void lbtnExportExcelAll_OnClick(object sender, EventArgs e)
{
//exporting data to excel document//
GridView gridview1 = new GridView();
gridview1.DataSource = DischargePatientRecordsForRightFilters;
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridview1.AllowPaging = false;
gridview1.DataBind();
gridview1.DataBound+=new EventHandler(gridview1_DataBound);
//Change the Header Row back to white color
gridview1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < gridview1.HeaderRow.Cells.Count; i++)
{
gridview1.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
gridview1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Thanks
Munna
abiruban
All-Star
16072 Points
2736 Posts
Re: Exporting Data from Grid to Excel
Mar 30, 2012 10:18 AM|LINK
HI,
http://www.c-sharpcorner.com/UploadFile/DipalChoksi/ExportASPNetDataGridToExcel11222005041447AM/ExportASPNetDataGridToExcel.aspx
http://www.codeproject.com/Articles/19284/Export-large-data-from-Gridview-and-Datareader-to
Thanks...
***DON'T FORGET TO CLICK “MARK AS ANSWER” ON THE POST IF HELPED YOU.
bhaskar.mule
Contributor
2270 Points
659 Posts
Re: Exporting Data from Grid to Excel
Mar 30, 2012 10:30 AM|LINK
hi
http://csharpektroncmssql.blogspot.com/2011/12/export-gridview-to-excel-in-aspnet.html
thanks
Site:Rare technical solutions
Munna1026
0 Points
4 Posts
Re: Exporting Data from Grid to Excel
Mar 30, 2012 10:45 AM|LINK
Hi abiruban,
Below links are having demos which are useful. Now I need to add Filter functionality to excel sheet header columns dynamically on button click itself.
Can you suggest me on this?
Thanks
Richey
Contributor
3816 Points
431 Posts
Re: Exporting Data from Grid to Excel
Apr 05, 2012 12:19 PM|LINK
Hi,
If you want to add the filter function to excel sheet it may hard to implement. You can’t use some controls in the excel file. Or you may give your idea clearly.
Mikedatawebc...
Member
12 Points
6 Posts
Re: Exporting Data from Grid to Excel
May 27, 2012 05:08 AM|LINK
This can be help to solve your problem :
http://www.datawebcoder.com/codeByLanguage/1521/Export_datagrid_to_Excel_in_asp_net.aspx
Thanks
Regards,
Datawebcode.com
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Exporting Data from Grid to Excel
May 27, 2012 07:17 AM|LINK
I think this is what you are looking for
http://www.aspforums.net/Threads/975633/Export-only-specific-columns-of-ASPNet-GridView-to-Excel/Answered#replies
Contact me