所以我的 ASPX 页面中有一个 GridView。
当我点击<asp:Button id="btnBindIt" runat="server" />
它绑定数据表如下:
theDataTable = GetAllTheRecords();
gvTheGridView.DataSource = theDataTable;
gvTheGridView.DataBind();
Note: theDataTable
是会员
private DataTable theDataTable;
这按预期工作。
现在,在 GridView 很好地显示后,我想将数据导出到 CSV,所以我现在单击<asp:Button id="btnExportIt" runat="server" />
运行代码:
exportToCsv(theDataTable);
but theDataTable
一片空白。
所以我尝试了
exportToCsv(gvTheGridView.DataSource)
这也是空的。
保存这些数据的标准方法是什么?我真的不想再次访问数据库,因为它是一个相当长的存储过程,并且用户已经等待过一次。
提前致谢!
类级别变量无法在回发时保持其值。
但是有两种方法可以维护页面回发上的数据:ViewState and Session State
。
但我建议在你的场景中将其放在ViewState
.
ViewState["theDataTable"] = theDataTable;
Session["theDataTable"] = theDataTable;
然后就可以在页面回发中访问它:
DataTable theDataTable = (DataTable)ViewState["theDataTable"];
DataTable theDataTable = (DataTable)Session["theDataTable"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)