回发后坚持的DataSource在GridView控件 [英] Persisting DataSource in GridView after PostBack

查看:198
本文介绍了回发后坚持的DataSource在GridView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在我的ASPX页面的GridView。

So I have a GridView in my ASPX page.

当我点击< ASP:按钮的ID =btnBindIt=服务器/> 它绑定一个数据表如下:

When I click <asp:Button id="btnBindIt" runat="server" /> it binds a datatable as follows:

theDataTable = GetAllTheRecords();
gvTheGridView.DataSource = theDataTable;
gvTheGridView.DataBind();

请注意: theDataTable 是一个成员

private DataTable theDataTable;

这正常工作。

现在,是很好的显示在GridView后,我想将数据导出为CSV,所以我现在点击&LT; ASP:按钮的ID =btnExportIt=服务器/&GT;它运行code

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);

theDataTable 为null。

所以,我想

exportToCsv(gvTheGridView.DataSource)

这也是空。

什么是永久保存此数据的标准方法是什么?我真的不希望再次击中DB,因为它是一个相当长的存储过程和用户​​已经等待了一次。

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.

在此先感谢!

推荐答案

感谢您的答案大家。

我避开把东西放入VeiwState或会话不必要的,所以我觉得坚持这一数据的最好的办法就是进行缓存。

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.

我觉得的MemoryCache 是这个最合适的地方,就是就是我最终实现它。

I think the MemoryCache is the most appropriate place for this, is is how I ended up implementing it.

这篇关于回发后坚持的DataSource在GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆