Dataset Caching

L

Larry Dodd

I have a datagrid that I have created a DataSet for and Bound the DataGrid
to it and the formatting of the data works fine when the page loads. I would
like to take the dataset that was created for the dataset and somehow keep
it in memory so that when I click on the Edit button in the EditColumn and
have to do Databind again I would like to use the dataset that is in memory
to rebind the datagrid to instead of having to reconnect to the database and
create the dataset again.

I already do this by putting the dataset in the ViewState but when I do a
DataBind in the Editcommand event the data is there but it loses all of its
formattig. I have stepped through the EditCommand procedure and it Databinds
ok but the Item_DataBound procedure is never called again. I assume that
this is the reason the data is not formatted correctly anymore. If I just
refresh the page it runs through the original procedure and the data is
formatted correctly like it was set in the DataGrid template. Any help would
be appreciated.
 
K

Ken Cox [Microsoft MVP]

Hi Larry,

The principle is pretty simple. You check if the cache contains the dataset. If
not you build it. Then you go ahead and use it.

This is pseudo code to show the idea.....

dim ds as dataset
ds=cache.("mydataset")
' Check if the dataset exists in the cache
if ds is nothing then
' do the stuff here to fill the dataset
da.fill(ds)
' put the dataset into the cache
cache.add("mydataset",ds,<otherstuff here like the cache length....>)
end if
datagrid1.datasource=ds

Does this help?

Ken
MVP [ASP.NET]

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/security_bulletins/ms03-026.asp



I have a datagrid that I have created a DataSet for and Bound the DataGrid
to it and the formatting of the data works fine when the page loads. I would
like to take the dataset that was created for the dataset and somehow keep
it in memory so that when I click on the Edit button in the EditColumn and
have to do Databind again I would like to use the dataset that is in memory
to rebind the datagrid to instead of having to reconnect to the database and
create the dataset again.

I already do this by putting the dataset in the ViewState but when I do a
DataBind in the Editcommand event the data is there but it loses all of its
formattig. I have stepped through the EditCommand procedure and it Databinds
ok but the Item_DataBound procedure is never called again. I assume that
this is the reason the data is not formatted correctly anymore. If I just
refresh the page it runs through the original procedure and the data is
formatted correctly like it was set in the DataGrid template. Any help would
be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,797
Members
47,344
Latest member
KamCrowthe

Latest Threads

Top