André Almeida Maldonado said:
Hi All.
I need to preserve the values of a datatable trough a page postback. Is this
possible?
Or
I need to add a row to a datagrid that has rows.
Thank's.....
Here is how I do this.
private DataTable data;
// Once data has be retrieved from database store it in Cache object (In
momory).
if ( !Page.IsPostBack )
{
this.data = db.MethodToGetDataTable();
// This stores the data for a time period of one minute. You probably
want to change this to something like one day or so.
HttpContext.Current.Cache.Insert( "NameOfCachedData", this.data, null,
DateTime.Now.AddMinutes(1), TimeSpan.Zero );
}
else
{
// On Postback restore data from Cache.
this.data = (DataTable)HttpContext.Current.Cache["NameOfCachedData"];
}
Regards,
Aaron Prohaska
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
Wrench Science Inc.
http://www.wrenchScience.com/
Phone: 510.841.4748 x206
Fax: 510.841.4708
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-