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

Posted on 2009-02-11
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

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now