Editing a DataList without updating the database

JRichmond

Freshman
Joined
Jul 30, 2004
Messages
40
Location
California
I have a data entry web form that has a couple datalists in the middle of it. I want to allow the user to add/edit/delete items in the datalists without any of the data being stored in the database until they click on the submit button to submit the entire webform.

What's the best way to do this?

I tried to create a dataset from the datalist's datasource on postback, but when I tried to access the dataset I got an invalid object error.

Any ideas?
 
I finally got this working using a session variable to store my dataset between page loads, but that seems like a kinda hokey way to do it. Does anyone know of a better way to update a datagrid or datalist without using a database?

Thanks!
 
JRichmond said:
I finally got this working using a session variable to store my dataset between page loads, but that seems like a kinda hokey way to do it. Does anyone know of a better way to update a datagrid or datalist without using a database?

I think that's very annoying all about this databound grids and list and saving their state accross postbacks. As I've migrated from desktop applications to ASP.NET, I've started to have headaches.

After postback, the DataSource of DataList is null, and the items are just recreated from ViewState. So, if you don't want to rebind it from database, you have a few possibilities. You can store your dataset in session, however, this is not recommended due to the size of data staying at the server then (but maybe the small datatables wouldn't be so bad ;). Or you can try to recreate your datatable from Items collection.

I'm not so familiar with DataList and have found it hard to do it at first glance, so if it's not possible so easily, there is still a possibility to turn the ViewState off and store the DataTable items to some unvisible ListBox or what. Really weird solution, I hope I was wrong about it :)
 
Rather than a session you could also store the data in the Cache object - this behaves more like an application variable so the data can be accessed from multiple sessions (great for data that doesn't change much - customers, employees, products etc), the items in the cache can also`be automatically expired based on your own criteria so they do not have`to be hanging around like a session variable.
 
Back
Top