How do I export a GridView to Excel and keep FilterExpression?

Posted on 2009-02-11
Medium Priority
Last Modified: 2013-11-07
I am exporting a GridView to Excel. I am also applying Filter Expressions to the GridView so that users can cut down the 800+ records in the GridView to the ones they are interested in.

But when I export, all 800+ records are exported, not just the ones currently filtered into the GridView.

How can I export the records with the filter in effect so that they user gets a file containing only those records that pass the filter and are displayed in the GridView?

Question by:davecove
1 Comment

Accepted Solution

davecove earned 0 total points
ID: 23615833
I figured it out... the GridView was loosing its FilterExpression on each page load (column sort, page turn, export linkButton_OnClick, etc). Clicking the export button was actually causing the GridView to loose the filter during the PostBack so it wasn't in effect when the export handler fired off.

I needed to store the FilterExpression in a session variable and reset the gridView's FilterExpression in Page_Load on PostBacks. With the filter now surviving the PostBack, the expect number of records were exported.


Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question