Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Im having an issue saving my dataTable to a ViewState. GetDataTable takes a SQL command and retrieve data from database. The problem I am facing is that the ViewState is NOT storing the datatable in the code below, however the dataTable has data stored within. I am using VB to write this code.

VB
Dim originDt As New DataTable()
originDt = GetDataTable()
ViewState("orignDt") = originDt



In another method I am trying to load the ViewState to a new datatable.

VB
If Not (ViewState("originDT") Is Nothing) Then
            Dim uploadDT As New DataTable
            uploadDT = DirectCast(ViewState("originDT"), DataTable)
            ReceiptGrid.DataSource = uploadDT
            ReceiptGrid.Rebind()
        End If


What I have tried:

I've tried to search other post for problems however it seems that everything I have is how it is suppose to be done :/
Posted

1 solution

I'm not sure if the issue is about the case sensitivity of your ViewState keys. You set the value to ViewState("orignDt") and you get the value using ViewState("originDT") - noticed the capital T.

Try to fix that so it will match the case. Also try to debug your codes, step into it and see if it hits in the line where you set the value to the ViewState. Do the same debugging for checking the value from ViewState.

Edit: Actually you had a different name of your ViewState key. The first one is misspelled. It should be ViewState("originDt") and not ViewState("orignDt") - Noticed the missing i.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900