TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Preethi Ganesh
NA
11
8.7k
GridView with Filter Export to Excel
Jun 29 2016 1:15 AM
Hi!
I have a asp.net gridview with filter on each of the column the Header. If I export it to excel, the cells with the filter(like text box, dropdownlist) also appears in Excel. How can I seperate the filter from the header while exporting to excel?
My Code below:
protected void ExportCSV(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
gvRecipeSetup.AllowPaging = false;
this.FilterWithPaging();
gvRecipeSetup.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in gvRecipeSetup.HeaderRow.Cells)
{
cell.BackColor = gvRecipeSetup.HeaderStyle.BackColor;
}
foreach (GridViewRow row in gvRecipeSetup.Rows)
{
row.BackColor = Color.White;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % 2 == 0)
{
cell.BackColor = gvRecipeSetup.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = gvRecipeSetup.RowStyle.BackColor;
}
cell.CssClass = "textmode";
}
}
gvRecipeSetup.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
Reply
Answers (
1
)
C# spell checker with suggestions for misspelled words
Custom User Login and Registration Page in ASP.Net MVC3 with