ListView with internal records

  • Thread starter Thread starter Jakob Lithner
  • Start date Start date
J

Jakob Lithner

I would like to have a webpage with a list of items for the user to send for
processing.

When the user enters the page I usually would like to enter a couple of
default items. Then it should be possible to edit, delete and insert items to
the list.
After all editing is ready, the list can be sent for processing.

I found out the ListView control looked like a great candidate. I added a
ListView and configured a corresponding ObjectDataSource. The
ObjectDataSource calls a handler class that creates the default entities. It
works fine so far.

But when I want to configure the Update, Delete and Insert commands I am
stuck. All examples are related to items being stored in database between
each call. But I don't want to store anything in database until the final
list is submitted.

Is this possible? Can I have a grid with records only "stored internally in
viewstate" and still allow editing?
 
Hi,

Regarding on your description, have you considered using a in-memory
dataset/datatable to hold the items/records you want to
manage(update/delete/insert) through the ListView(or other databound
control)? Thus, you can store the datatable/dataset either in page's
viewstate or SessionState(store in viewstate will cause the page's response
size increase much.

#Insert/Update/Delete operations on dataset
http://forums.asp.net/p/1156913/2234796.aspx#2234796

#How to bind GridView and DropDownList controls using DataTable object
http://www.devasp.net/net/articles/display/278.html

#ASP.Net Bind GridView to DataTable
http://programming.top54u.com/post/ASP-Net-Bind-GridView-to-DataTable.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).


--------------------
 
I would like to have a webpage with a list of items for the user to send for
processing.

When the user enters the page I usually would like to enter a couple of
default items. Then it should be possible to edit, delete and insert items to
the list.
After all editing is ready, the list can be sent for processing.

I found out the ListView control looked like a great candidate. I added a
ListView and configured a corresponding ObjectDataSource. The
ObjectDataSource calls a handler class that creates the default entities.It
works fine so far.

But when I want to configure the Update, Delete and Insert commands I am
stuck. All examples are related to items being stored in database between
each call. But I don't want to store anything in database until the final
list is submitted.

Is this possible? Can I have a grid with records only "stored internally in
viewstate" and still allow editing?

Hi Jakob,

I think you can easily do this. On initial load, check viewstate and
create a new dataset if there is no data and bind the listview to the
dataset. If viewstate has already some data, retrieve the dataset from
there

if (ViewState["dSet"] != null) {

System.IO.StringReader sr = new System.IO.StringReader((string)
(ViewState["dSet"]));
dSet.ReadXml(sr);

} else {

System.IO.StringWriter sw = new System.IO.StringWriter();

// Write the DataSet to the ViewState property.
dSet.WriteXml(sw);
ViewState["dSet"] = sw.ToString();

}

http://msdn.microsoft.com/en-us/library/aa287542.aspx
http://msdn.microsoft.com/en-us/library/aa287539.aspx

After that you should be able to work with listview as with a
database.

Hope this helps
 
Back
Top