如何保存单选按钮的状态?
我的问题是:如何将单选按钮的状态(选中或未选中)导出到文本文件并将其读回,以便按钮呈现保存的状态?
我觉得这可能很简单,但我完全不知所措。
任何帮助将不胜感激!
My question is: How do I export the status of a radio button (checked or not) to a text file and read it back in so the button assumes the saved status?
I feel it might be something simple but am at a complete loss.
Any help will be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将单选按钮的
Checked
属性的布尔值保存为整数:读回它并将该值分配回
Checked
属性。Save the boolean value of the radio button's
Checked
property as an integer:Read it back in and assign the value back to the
Checked
property.好吧,您可以存储按钮的状态,然后 将其状态写入文本文件,然后从文本文件中读取其状态。您将从文本文件中读取最后一行,然后您将有一些关于下一步要做什么的选项,例如使用
if 语句
根据您从文本中读取的内容来决定要做什么文件。这两个链接应该对你有帮助。剩下的就看你的逻辑需求了。Well, you could store the state of the button, then Write its state to a text file, then read its state from the text file. You would read the last line from the text file, and then you would have a few options on what to do next, such as use an
if statement
to decide what to do given what you read from the text file. Those two links should help you. The rest is up to your logic needs.您很可能需要将单选按钮的状态保存到变量中,将该变量写入文本文件并将该文本文件读回到程序中。
此时,您需要在文本文件和单选按钮之间使用一些解释器来更改其状态。
More than likely, you need to save the Radio button's state to a variable, write the variable to a text file and read the text file back into your program.
At that point you'll need some interpreter between the text file and the Radio Button to change the its state.
您需要在什么情况下执行此操作?在大多数情况下,您将用户数据保存在数据库中,键是他们的用户 ID。如果您这样做是因为您需要另一个网页中的值并且您正在使用 asp,请查看 viewstate。请记住,与在内存中相比,文件系统 io 的速度慢得可怕。
In what context would you need to do this? In most cases you save user data in a database, with the key being their userid. If you are doing this because you need the value in another web page and you are using asp, check out viewstate. Remember that doing filesystem io is hideously slow compared to in memory.