只能透過 ViewState / Session 等儲存機制來記憶上一次的排序方向.
例如在 OnSorting 的事件中使用 Session做狀態儲存:
1 2 3 4 5 6 7 8 9 10 11 | if (Session[ "SortDirection" ] == null ) { //因預設是ASC,所以觸發此事件時, 應設定為DESC Session[ "SortDirection" ] = SortDirection.Descending; } else { //ASC<-->DESC(對調) Session[ "SortDirection" ] = (((SortDirection)Session[ "SortDirection" ]) == SortDirection.Ascending) ? SortDirection.Descending : SortDirection.Ascending; } Session[ "SortExpression" ] = e.SortExpression; |
沒有留言:
張貼留言