所以我有一个从互联网上“借来”的方法,我在我的许多页面上使用它来处理网格列的排序。
private string GetSortDirection(string column)
{
// By default, set the sort direction to ascending.
string sortDirection = "ASC";
// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
现在它工作得很好,但是,我必须将它复制到我想从中调用它的每个页面,因为它引用了视图状态。所以我想将它移动到我的助手类并将其存储在会话状态中,但是,我不能在助手类中引用任何状态。
他们有什么方法可以从帮助类访问会话吗?我可以通过引用传递会话状态吗?