DataTable

  • Thread starter Thread starter André Almeida Maldonado
  • Start date Start date
A

André Almeida Maldonado

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.....
 
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.....

1) yes, there are various ways of persisting data/state. Session or
ViewState to name just a couple. I can't remember, you may need to put
it in a DataSet (which is serializable) and persist that instead...try
that if it initially doesn't work.

2) see this article:
http://www.dotnetjunkies.com/Tutorial/C0DD0D9A-8907-4117-BBF2-4C407AA83574.dcik
 
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
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
 
Back
Top