Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ViewState and DataTable

Reply
Thread Tools

ViewState and DataTable

 
 
Peter Hemmingsen
Guest
Posts: n/a
 
      10-22-2009
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


 
Reply With Quote
 
 
 
 
Linda Smith
Guest
Posts: n/a
 
      01-04-2010
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:

On Thursday, October 22, 2009 11:30 AM
Peter Hemmingsen wrote:

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/tutorials...-html-con.aspx
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort a datatable and create a new datatable Fredrik Rodin ASP .Net 3 09-28-2007 07:28 AM
How can I add a row from a typed datatable to another instance of that typed datatable? Ersin Gençtürk ASP .Net 1 10-06-2004 01:11 PM
Create a Datatable from a SQL datatable column shema? jg ASP .Net 1 08-17-2004 09:43 PM
Casting DataTable to class inherit from DataTable =?Utf-8?B?Qmx1ZWZsb3dlcg==?= ASP .Net 0 04-02-2004 05:41 AM
Adding DataTable Rows To another DataTable J. Babe ASP .Net 1 08-15-2003 05:04 PM



Advertisments