まず最初に言いたいのは、ぐっ!!
基本的に、スレッドは、キャッシュが有効になっている一般的なリストをソートできないことに関するものです。返信を組み合わせてみましたが、うまくいきません。私は非常に近いようですが、まだこれまでのところ...
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//What goes in this area?
CheckExpiredCacheKey(argRefresh);
ObjectDataSource1.SelectParameters["sortBy"].DefaultValue = string.Format("{0} {1}", e.SortExpression, e.SortDirection == SortDirection.Ascending ? "ASC" : "DESC");
e.Cancel = true;
}
public void CheckExpiredCacheKey(string ckey)
{
if (Cache[ckey] == null)
Cache[ckey] = new object(); //Set Cache key which will b used to manually expire ODS cache
if (!IsPostBack && Request.QueryString["refresh"] == "1")//check refresh flag
{
//Cache.Remove(ckey);//NOT NEEDED: use the following instead
Cache[ckey] = new object();// Needed otherwise it'll call Grid-populate twice
}
}
この方法でジェネリック リストを並べ替えてキャッシュしようとすると、sortBy 文字列が常に空白になる Select メソッドを次に示します。
[DataObject(true)]
public class BusinessLogic
{
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static List<Customer> GetCustomers(int financeId, int startIndex, int pageSize, string sortBy)
{
return DataAccess.GetCustomers(financeId, startIndex, pageSize, sortBy);
}