I have a repeater that displays financial data and prices for various stocks.
On this page, I also have an "export" button that needs to take the data ~on the screen~ and convert it into a CSV for the user.
The problem is, after I databind my list of "Stock" entities:
List<Stock> stocks = GetStocks()
rptStockList.DataSource = stocks;
rptStockList.DataBind();
The data is not persisted on postback.
Also, the data on this page is constantly being updated via an UpdatePanel and a Timer control (being re-databound each time). Every 30 seconds the prices displayed for the various stocks in the repeater control change.
Now, I have a linkbutton that has a click event method in the code-behind that is supposed to export the ~data on the screen~ for the user. I need to grab the current values for the list of stocks last databound to the repeater. I can't simply go grab the latest values from the database because those will have been changed in the time between the last refresh.
protected void lbtnExportStocks_Click(object sender, EventArgs e)
{
// No longer have the stock data used in the repeater control
ExportStocksToExcel();
}
I know that ASP.NET doesn't persist the datasource for the repeater on post-back but I need to still be able to either re-construct this list of Stock entities so I can send them the CSV or I need persist it in some way.
I don't want to do anything that is too heavy handed in terms of performance because during certain days of the week this application can have some heavy usage.
What is the proper solution to this type of situation? Should I iterate through the Repeater's "Items" collection and reconstruct the Stock entities?