我怎么可以存储一个GridView单元格值到会话变量? [英] How can I store a GridView cell value to a session variable?

查看:204
本文介绍了我怎么可以存储一个GridView单元格值到会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个GridView的选择行的值存储到一个会话变量?

How would I store the value of a GridView's selected rows to a session variable?

推荐答案

在一个侧面说明:我能stronly劝你的不可以使用会话状态

On a side note: can I stronly advise you NOT to use the session state.

除非你使用它作为其中数据缓存为当前用户一个商店,你可以检索回的任何例如从时间一个数据库中。

Unless you are using it as a store where data is cached for the current user, which you can retrieve back at any time from e.g. a database.

如果没有,会议会回来的的你。在某些时候,会有留下的浏览器打开超过会话生命更长的时间,用户(例如,他们得到了一个电话,出去吃午饭赶时间,匆匆来一补......)。而当他们回来,他们希望完成他们在做什么。如果你不能在这一点上还原所有会话数据的时候,你将不得不重新定向用户,以重新开始呢(你的用户来说是非常恼人的),否则你将失去一些信息(很embarrasing),或者最糟糕的的情况下,和最常见的情况:您的应用程序将不再工作,崩溃(只是简单的:非常糟糕)。

If not, the "session" will come back and bite you. At some point there will be a user that leaves the browser open for longer time than your session lives (e.g. they get a telephone call, go out to lunch in a hurry, rush of to a meeting...). And when they return, they wish to complete what they are doing. And if you cannot restore all of your session data back at that point, you will either have to redirect your user to start over again (very annoying for your users), or you will have lost some information (very embarrasing), or the worst case, and most common case: your application will no longer work and crash (just plain: very bad).

这是一个更好的方法来定义存储您的状态小序列化对象(查询参数,选定项目等),使用ASP.NET视图状态到该状态存储在页请求之间。请注意,大多数ASP.NET控件已经使用视图状态来存储数据。然后,禁用ViewState中在页面的网格,以大大降低您的视图状态的数据量,并在每个请求请求数据(在这里是安全的使用会话或ASP.NET缓存以提高应用程序的性能) 。你将有一个更强大和更具扩展性的应用程序。

It is a better approach to define small serializable objects that store your state (query parameters, selected items, etc) and use ASP.NET Viewstate to store that state across page requests. Note that most ASP.NET controls already use the viewstate to store their data. Then disable the Viewstate of your grids in the page, to vastly reduce the amount of data in your viewstate, and request the data upon each request (here it is safe to use the session or ASP.NET cache to improve performance of your application). You will have a much more robust and much more scalable application.

有更多的工作,但它会回报非常快,而且许多倍。

It is more work, but it will pay back very fast, and many times over.

这篇关于我怎么可以存储一个GridView单元格值到会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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