Maintain Datatable values during postbacks

B

bijoy

My page has a Listbox called Rooms, a text field called chairPerson and
a button called Add.

When Add is clicked, the script needs to display the selected info in a
datagrid.

For example, if the user selects Rooms 1,5 and 7, and enters Bijoy for
chairperson and clicks Add, a datagrid on the page should display the
following:

1, Bijoy
5, Bijoy
7, Bijoy

THEN if the user select Rooms 2 and 3, sets chairperson to Jeff and
clicks Add, the datagrid should display:

1, Bijoy
5, Bijoy
7, Bijoy
2, Jeff
3, Jeff

To accomplish this, I am using a DataTable. When Add is clicked, I add
"rows" to the DataTable, then bind the datagrid to this DataTable.

It works fine, except for a "memory loss" problem - meaning, it forgets
what was originally in the datagrid.

How can I use ViewState to save the DataTable across postbacks?

Thanks in advance.

BIjoy
 
S

S. Justin Gengo

Bijoy,

You'll need to persist the datatable by storing the object somewhere.

If it won't get too long I would place the datatable inside of a dataset
(which is serializable) and store the dataset in viewstate. Then whenever
you are adding rows to your datatable first get the dataset back out of
viewstate, add the rows, and then put it back into viewstate again.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
B

bijoy

Actually I was able to add the datatable to the viewstate, and retrive
it after every postback, add new rows to it, then bind, then add to the
viewstate.
 
S

S. Justin Gengo

Bijoy,

Great! (you must be using Visual Studio 2005?) If so that accounts for the
difference, in the latest version datatables are serializable. They weren't
before.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top