视图状态中的数据表无法正常工作 [英] Datatable in view state not working
问题描述
您好我在将dataTable保存到ViewState时遇到问题。 GetDataTable接受SQL命令并从数据库中检索数据。我面临的问题是ViewState是 NOT 在下面的代码中存储数据表,但是dataTable存储了数据。我使用VB编写此代码。
Dim originDt < span class =code-keyword> As New DataTable()
originDt = GetDataTable()
ViewState( orignDt)= originDt
在另一种方法中,我试图将ViewState加载到新数据表。
如果 不(ViewState( < span class =code-string> originDT) Nothing )然后
Dim uploadDT 作为 新 DataTable
uploadDT = DirectCast (V iewState( originDT),DataTable)
ReceiptGrid.DataSource = uploadDT
ReceiptGrid.Rebind()
结束 如果
我尝试了什么:
我试图在其他帖子中查找问题但似乎我所拥有的一切都是如何完成的:/
我不确定问题是否与您的ViewState的区分大小写有关键。您将值设置为ViewState(orignDt)
并使用ViewState(originDT)
获取值 - 注意到大写T
。
尝试解决这个问题,以便它符合案例。还尝试调试代码,进入它并查看它是否在您将值设置为ViewState
的行中命中。执行相同的调试以检查ViewState
中的值。
编辑:其实你有一个不同的名字ViewState
键。第一个拼写错误。它应该是ViewState(originDt)
而不是ViewState(orignDt)
- 注意到缺少的我
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.
Dim originDt As New DataTable()
originDt = GetDataTable()
ViewState("orignDt") = originDt
In another method I am trying to load the ViewState to a new datatable.
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 :/
I'm not sure if the issue is about the case sensitivity of your ViewState keys. You set the value toViewState("orignDt")
and you get the value usingViewState("originDT")
- noticed the capitalT
.
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 theViewState
. Do the same debugging for checking the value fromViewState
.
Edit: Actually you had a different name of yourViewState
key. The first one is misspelled. It should beViewState("originDt")
and notViewState("orignDt")
- Noticed the missingi
.
这篇关于视图状态中的数据表无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!