DataTable in ViewState

  • Thread starter Thread starter Pradeep
  • Start date Start date
P

Pradeep

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,

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
 
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
 
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
 
Back
Top