Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ArrayList into ViewState

ArrayList into ViewState

Scheduled Pinned Locked Moved C#
questiondatabasehelpannouncement
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treuveni
    wrote on last edited by
    #1

    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

    T S N V 4 Replies Last reply
    0
    • T treuveni

      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

      T Offline
      T Offline
      treuveni
      wrote on last edited by
      #2

      i'v just red that i cannot use ArrayList in ViewState, because ViewState needs a serializable object, and ArrayList is not one, because i cannot tell if it's components are serializable. Is there another way to do this? :(

      1 Reply Last reply
      0
      • T treuveni

        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

        S Offline
        S Offline
        Shani Natav
        wrote on last edited by
        #3

        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.

        N 1 Reply Last reply
        0
        • T treuveni

          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

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You 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

          1 Reply Last reply
          0
          • S Shani Natav

            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.

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • T treuveni

              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

              V Offline
              V Offline
              Vivek H
              wrote on last edited by
              #6

              If 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... ~V

              modified on Monday, August 23, 2010 9:35 AM

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups