视图状态中的数据表无法正常工作 [英] Datatable in view state not working

查看:108
本文介绍了视图状态中的数据表无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在将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 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.


这篇关于视图状态中的数据表无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆