ViewState and DataTable

P

Peter Hemmingsen

Hi

Im storing a (very small) DataTable in ViewState as follows:

DataTable dt = new DataTable();
DataRow dr = dt.NewRow();
dt.Rows.Add (dr);
ViewState ["MyTable"]=dt;

When a button is pressed I read the DataTable from ViewState and add a row:

DataTable dt=ViewState["MyTable"];
DataRow dr = dt.NewRow();
dt.Rows.Add (dr);

at this point I would have saved the new datatable dt in ViewState but using
the debugger I can see that the ViewState datatable is already modified. I
would have expected

DataTable dt=ViewState["MyTable"];

to make a copy but it looks more like a reference?
I would appreciate if somebody could explain this,- thanks.

Peter
 
L

Linda Smith

I experienced the same thing. The viewstate seems to change with the datatable. Do you have a solution for this?



Peter Hemmingsen wrote:

ViewState and DataTable
22-Oct-09

H

Im storing a (very small) DataTable in ViewState as follows

DataTable dt = new DataTable()
DataRow dr = dt.NewRow()
dt.Rows.Add (dr)
ViewState ["MyTable"]=dt

When a button is pressed I read the DataTable from ViewState and add a row

DataTable dt=ViewState["MyTable"]
DataRow dr = dt.NewRow()
dt.Rows.Add (dr)

at this point I would have saved the new datatable dt in ViewState but usin
the debugger I can see that the ViewState datatable is already modified.
would have expecte

DataTable dt=ViewState["MyTable"]

to make a copy but it looks more like a reference
I would appreciate if somebody could explain this,- thanks

Peter

Previous Posts In This Thread:

ViewState and DataTable
H

Im storing a (very small) DataTable in ViewState as follows

DataTable dt = new DataTable()
DataRow dr = dt.NewRow()
dt.Rows.Add (dr)
ViewState ["MyTable"]=dt

When a button is pressed I read the DataTable from ViewState and add a row

DataTable dt=ViewState["MyTable"]
DataRow dr = dt.NewRow()
dt.Rows.Add (dr)

at this point I would have saved the new datatable dt in ViewState but usin
the debugger I can see that the ViewState datatable is already modified.
would have expecte

DataTable dt=ViewState["MyTable"]

to make a copy but it looks more like a reference
I would appreciate if somebody could explain this,- thanks

Peter


Submitted via EggHeadCafe - Software Developer Portal of Choice
Preventing extra HTML Content in File Downloads
http://www.eggheadcafe.com/tutorial...e-f3dcccf496ad/preventing-extra-html-con.aspx
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top