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

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?

Who is Participating?
davecoveAuthor Commented:
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.