asp.net gridview:读取值和持久状态
我有一个将数据绑定到自定义对象列表的网格视图。在客户端,用户可以在文本框中输入价格值,然后单击网格视图中每一行的复选框。 gridview支持分页,包含几十个页面。当网格视图中的数据发生更改时,我不一定要更改数据库中的条目,因为用户最终可能会取消页面,但我确实想记住(暂时)在其他页面上检查的内容。
我试图弄清楚当用户单击“提交”时如何读取 gridview 中所有页面的所有值。我可以为文本框和复选框设置事件处理程序,但我仍然需要存储自定义对象的修改列表。在 ASP 中,这通常是在应用程序缓存中完成还是应该将内容存储在视图状态中?
I have a gridview that is databound to a list of custom objects. On the client side, the user can enter a price value in a textbox and click on a checkbox for every row in the gridview. The gridview supports pagination and contains dozens of pages. When data is changed in the gridview I don't necessarily want to change entries in the database because the user could end up cancelling out of the page, but I do want to remember (for now) what was check on other pages.
I'm trying to figure out how to read all the values across all the pages in the gridview when the user clicks submit. I could setup event handlers for the textboxes and checkboxes but I still need to store the modifed list of custom objects. In ASP, is this normally done in the application cache or should I be storing stuff in the viewstate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将值存储在 ViewState 或 Session 中。
当需要更新时,您可以更新数据库。
通常不会在应用程序缓存中完成此操作,因为数据只应在用户会话期间保留。
IE
加载您的产品和产品列表将其绑定到网格视图。还将产品存储到您的 Viewstate。当需要添加、更新或删除产品时,您可以对 ViewState 中的 Products 对象进行更改。
在 SaveClick 事件中,您从 ViewState 读取产品并更新数据库。
请务必检查并发问题。
You can store the values in ViewState or Session.
When it's time to update, you update the DB.
It's not normally done in the application cache since data should only persist for the user's session.
i.e.
Load up your list of Products & Bind it to the gridview. Also store the Products to your Viewstate. When it's time to add,update or delete a product, you make the changes to the Products object in ViewState.
On your SaveClick Event you read the products from ViewState and update the DB.
Just be sure to check for concurrency issues.