如何在页面之间移动时保持签入复选框 [英] How to keep check in checkbox when moving between pages

查看:55
本文介绍了如何在页面之间移动时保持签入复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你返回页面时,你检查了gridview中的一些行,保留了这个检查

i做了两个sub并在pageindex中调用它



这个错误::

识别预期

when return to the page you checked some rows in gridview keeping this check
i made two sub and call it in pageindex

this error::
identifire expected

(If dt.Rows(x).("check1") = 1 Then
)

(DT.Rows(i).("check1") = 1
)
(DT .Rows (i).("check1")=0
)





sql server我做这个选择的陈述:::







in sql server i make this select statment :::


select * from setup where setup_type=@setup_type
		select 0 as check1





我尝试了什么:





What I have tried:

Protected Sub CHECK1()
        Dim n As String
        Dim dt As DataTable = Session("LoadData")
        For x = 0 To GridNatRel.Rows.Count - 1
            If dt.Rows(x).("check1") = 1 Then
                CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked = True
            Else
                CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked = False
            End If
        Next

    End Sub
    Protected Sub CHECK2()
        Dim DT As DataTable = Session("LoadData")
        For i = 0 To GridNatRel.Rows.Count - 1
            If CType(GridNatRel.Rows(i).FindControl("CheckBox1"), CheckBox).Checked = True Then
                DT.Rows(i).("check1") = 1
            Else
                DT .Rows (i).("check1")=0
            End If
        Next
    End Sub

推荐答案

有很多方法,我想指出其中两个,更现代的方法。我喜欢他们因为他们更普遍;特别是,它们不依赖于您在服务器端使用的技术,并且即使您根本没有服务器端也适用(假设某些应用程序)。



一种方法是使用浏览器功能,只在客户端拥有多个页面并在它们之间共享数据。这可以使用 Web存储完成: https://en.wikipedia.org/wiki/Web_storage [ ^ ]。



您可以选择 window.localStorage window.sessionStorage

https://developer.mozilla.org/en-US/docs/Web/API / Web_Storage_API [ ^ ],

https://developer.mozilla.org / en-US / docs / Web / API / Window / sessionStorage [ ^ ],

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage [ ^ ]。



会话存储更容易,因为您不需要从浏览器中清除数据;如果您没有这样做或只是忽略此问题,则会话结束后,浏览器最终会删除数据。使用本地存储,您必须在代码中删除此数据,以避免污染您的浏览器数据,但如果您想在会话之间继续测验,则可能需要它。



现在,Web存储本质上只适用于字符串。很可能,您更愿意将数据存储在更复杂的结构中,可能只需一个键。然后您可以使用序列化 http://en.wikipedia.org/wiki/Serialization [ ^ ])。怎么样?当然是JSON; JSON.stringify JSON.parse

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON [ ^ ],

https:// developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify [ ^ ],

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse [ ^ ]。



请注意,您不需要处理JSON字符串本身,只需序列化和反序列化数据。在我的文章中,您可以找到显示该技术的简单代码,使用JSON的Web存储: JavaScript计算器, 7。动态严格模式切换和Web存储



另一种方法是在一个页面中开发整个。如果你打破较小部分的内容并一次显示一个部分,隐藏其他部分,这很容易实现。在这种方法中,您不需要在页面之间交换任何数据。另请参阅: https://en.wikipedia.org/wiki/Single-page_application [ ^ ]。



-SA
There is a good number of approaches, I want to point out two of them, more modern ones. I like them because they are more universal; in particular, they don't depend on what technology you use on the server side, and applicable even if you don't have server side at all (let's say, for some applications).

One approach is having multiple pages and sharing data between them purely on the client side, using just the browser features. This can be done using Web storage: https://en.wikipedia.org/wiki/Web_storage[^].

You can chose between window.localStorage and window.sessionStorage:
https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API[^],
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage[^],
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage[^].

Session storage is much easier, because you won't need to clear the data from the browser; if you fail to do so or just ignore this problem, the data will be eventually removed by the browser after the session has ended. With local storage, you will have to remove this data in your code, to avoid contamination of your browser's data, but you may need it if you want to continue your quiz between sessions.

Now, Web storage, essentially, works only with strings. Very likely, you will prefer storing data in more complex structures, possibly all by one key. Then you can use serialization (http://en.wikipedia.org/wiki/Serialization[^]). How? JSON, of course; JSON.stringify and JSON.parse:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON[^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify[^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse[^].

Note that you don't need to deal with JSON string itself, you only serialize and deserialize your data. In my article, you can find the simple code showing the technique, Web storage with JSON: JavaScript Calculator, 7. Dynamic Strict Mode Switching and Web Storage.

Another approach is to develop the whole quite in a single page. It's pretty easy to achieve if you break the content in smaller part and show one part at a time, hiding other parts. In this approach, you won't need to exchange any data between pages. See also: https://en.wikipedia.org/wiki/Single-page_application[^].

—SA


这篇关于如何在页面之间移动时保持签入复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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