Professional Web Applications Themes

DataTable in ViewState - ASP.NET General

Hi, I am storing the DataTable in a ViewState. ViewState("mydata") = dsRedemption.T_Redemption_Dtl Then I am casting the ViewState into a DataTable variable. Dim x As New DataTable x = CType( ViewState("mydata"), DataTable) This is giving me a error where it's not allowing me to Cast it. If i directly see the data in the ViewState("mydata") it's perfectly fine. First of all, is it advisable to store the DataTable in the ViewState ??? Any idea ??? Pradeep...

  1. #1

    Default DataTable in ViewState

    Hi,

    I am storing the DataTable in a ViewState.

    ViewState("mydata") = dsRedemption.T_Redemption_Dtl

    Then I am casting the ViewState into a DataTable variable.

    Dim x As New DataTable
    x = CType( ViewState("mydata"), DataTable)

    This is giving me a error where it's not allowing me to Cast it. If i
    directly see the data in the ViewState("mydata") it's perfectly fine. First
    of all, is it advisable to store the DataTable in the ViewState ???

    Any idea ???

    Pradeep



    Pradeep Guest

  2. #2

    Default Re: DataTable in ViewState

    Pradeep,

    Depending on the size of the table it could make for a very slow load of
    your page on the client, but other than watching the table's size it should
    be fine.

    Now .Net might be getting confused because when you save the table to
    viewstate you are referencing it through the dataset it's in. Perhaps it
    thinks you are saving the entire dataset?

    Try setting the table to a new container and then saving that container to
    viewstate:

    Dim MyDataTable As DataTable = dsRedemption.T_Redemption_Dtl

    ViewState("mydata") = MyDataTable

    Dim x As New DataTable
    x = CType( ViewState("mydata"), DataTable)

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Pradeep" <com> wrote in message
    news:ujNkCn$phx.gbl... 
    First 


    S. Guest

  3. #3

    Default Re: DataTable in ViewState

    Hi Justin,

    Now I am trying to store the DataTable into a new contrainer and then to the
    ViewState. This time it doesn't raise any error. But after casting, my "x"
    value is becoming "Nothing" even though data is available in the ViewStage
    variable.

    Where is the problem ???

    Pradeep

    "S. Justin Gengo" <com> wrote in message
    news:#i$phx.gbl... 
    should 
    > First 
    >
    >[/ref]


    Pradeep Guest

  4. #4

    Default Re: DataTable in ViewState

    Pradeep,

    I should have noticed this originally. When you dim x don't dim it as "New"

    Dim x As DataTable

    x = CType(ViewState("MyData"), DataTable)

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Pradeep" <com> wrote in message
    news:%phx.gbl... 
    the 
    "x" 
    > should [/ref]
    to 
    > > First 
    > >
    > >[/ref]
    >
    >[/ref]


    S. Guest

Similar Threads

  1. Question DataTable
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: July 28th, 05:38 AM
  2. Failed to load viewstate. The control tree into which viewstate...
    By Josema in forum ASP.NET Building Controls
    Replies: 5
    Last Post: April 13th, 07:48 AM
  3. Viewstate errors... how do I get viewstate working?
    By mark in forum ASP.NET Building Controls
    Replies: 0
    Last Post: February 20th, 02:17 PM
  4. Insert a Datatable or Datagrid into ViewState?
    By Stephajn Craig in forum ASP.NET General
    Replies: 1
    Last Post: July 22nd, 11:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139