So I have a GridView in my ASPX page.
When I click <asp:Button id="btnBindIt" runat="server" /> it binds a datatable as follows:
theDataTable = GetAllTheRecords();
gvTheGridView.DataSource = theDataTable;
gvTheGridView.DataBind();
Note: theDataTable is a member
private DataTable theDataTable;
This works as expected.
Now, after the GridView is displayed nicely, I want to export the data to CSV, so I now click the <asp:Button id="btnExportIt" runat="server" /> which runs the code:
exportToCsv(theDataTable);
but theDataTable is null.
So I tried
exportToCsv(gvTheGridView.DataSource)
Which is also null.
What’s the standard way of persisting this data? I don’t really want to hit the DB again as it’s quite a long SPROC and the user has already waited once.
Thanks in advance!
Thanks for the answers everyone.
I steer clear of putting stuff into the VeiwState or session unnecessarily, so I think the best way to persist this data is to Cache it.
I think the MemoryCache is the most appropriate place for this, is is how I ended up implementing it.