开发者

how to destroy session in asp.net for grid view

i have set sesssion lik this

Session["page"开发者_如何学编程 + GridView1.PageIndex] = values;

Now hwen next time on ok button click hen i regenerate i fresh copy of gridview. It's first column which hold the checkbox automatically takes values from the checkbox. So i want that the session should be destroyed how to achieve this for all page index of datagrid.


Session.Abandon();

The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.

A worthy note though:

When the Abandon method is called, the current Session object is queued for deletion but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to the Abandon method but not in any subsequent Web pages.

From MSDN.


Edit 1:

In reply to not wanting to destroy the entire session, Can you not simply remove the item from the session then? E.g.: Session.Remove("page" + GridView1.PageIndex);?


Edit 2:

Session.Clear() removes all keys and objects from the current session.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜