ArrayList into ViewState
-
Hi, I'm trying to populate viewState with ArrayList like this-
ArrayList list = ConvertDataTableToArrayList(dt); ViewState["QueryList"] = list; public ArrayList ConvertDataTableToArrayList(DataTable st) { ArrayList query = new ArrayList(dt.Rows.Count); foreach (DataRow row in dt.Rows) { query.Add(row); } return query; }
But i'm getting this error-Type 'System.Data.DataRow' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
How can i need to solve it? 10x -
Hi, I'm trying to populate viewState with ArrayList like this-
ArrayList list = ConvertDataTableToArrayList(dt); ViewState["QueryList"] = list; public ArrayList ConvertDataTableToArrayList(DataTable st) { ArrayList query = new ArrayList(dt.Rows.Count); foreach (DataRow row in dt.Rows) { query.Add(row); } return query; }
But i'm getting this error-Type 'System.Data.DataRow' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
How can i need to solve it? 10x -
Hi, I'm trying to populate viewState with ArrayList like this-
ArrayList list = ConvertDataTableToArrayList(dt); ViewState["QueryList"] = list; public ArrayList ConvertDataTableToArrayList(DataTable st) { ArrayList query = new ArrayList(dt.Rows.Count); foreach (DataRow row in dt.Rows) { query.Add(row); } return query; }
But i'm getting this error-Type 'System.Data.DataRow' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
How can i need to solve it? 10xIt's not the ArrayList the causes the problem it's the DataRow which is not serialiazable. 1) Try using Session variables (Session["QueryList"]) 2) Make a localized object that has properties that match the datarow columns and serialize the datarow to the object, and use a System.Collections.Generic.List if possible.
-
Hi, I'm trying to populate viewState with ArrayList like this-
ArrayList list = ConvertDataTableToArrayList(dt); ViewState["QueryList"] = list; public ArrayList ConvertDataTableToArrayList(DataTable st) { ArrayList query = new ArrayList(dt.Rows.Count); foreach (DataRow row in dt.Rows) { query.Add(row); } return query; }
But i'm getting this error-Type 'System.Data.DataRow' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
How can i need to solve it? 10xYou should be trying to store your data in viewstate anyway. ViewState should only be for small amounts of information, perhaps an ID to lookup the data again. Remember, viewstate is writtent ot he page so the larger it is the slower your pages will download and render.
I know the language. I've read a book. - _Madmatt
-
It's not the ArrayList the causes the problem it's the DataRow which is not serialiazable. 1) Try using Session variables (Session["QueryList"]) 2) Make a localized object that has properties that match the datarow columns and serialize the datarow to the object, and use a System.Collections.Generic.List if possible.
Shani Natav wrote:
Try using Session variables (Session["QueryList"])
Just shifting the problem from one storage mechanism to another. It still must be serializable.
I know the language. I've read a book. - _Madmatt
-
Hi, I'm trying to populate viewState with ArrayList like this-
ArrayList list = ConvertDataTableToArrayList(dt); ViewState["QueryList"] = list; public ArrayList ConvertDataTableToArrayList(DataTable st) { ArrayList query = new ArrayList(dt.Rows.Count); foreach (DataRow row in dt.Rows) { query.Add(row); } return query; }
But i'm getting this error-Type 'System.Data.DataRow' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
How can i need to solve it? 10xIf you are facing problem with iterating the row then you can try the below code,
for (int rowCount = 0; rowCount < dataTable.Rows.Count;rowCount++ ) { query.Add(dataTable.Rows[rowCount]); } ViewState["QueryList"] = query;
and reverse----
list = (ArrayList)ViewState["QueryList"]; for (int rowCount = 0; rowCount < list.Count; rowCount++) { DataRow dataRW = (DataRow)list[rowCount]; //add it to desired data table... :) }
Have a good day... ~Vmodified on Monday, August 23, 2010 9:35 AM