2011-12-26 4 views
0

私はGridViewのソースをストアドプロシージャの結果に設定しました。これは基本的にデータ可能です。ASPxGridView datatableキャッシング

ASPxGridView1.DataSource = dt1; 
ASPxGridView1.DataBind(); 

これはボタンクリックで発生しています。最初のステップではOKですが、並べ替え、フィルタリング、または結果の次のページに移動しようとすると、gridviewは空です。結果を表示するには、(データバインドを明示的に呼び出すために)ボタンをクリックする必要があります。

私の質問は、ストアドプロシージャから何らかの形でデータテーブルをキャッシュする方法なので、ソートやページの変更ごとにデータをバインドする必要はありません。

ありがとうございました。

+0

MSDNをチェックしていますか? [DataSourceコントロールを使用したキャッシュ](http://msdn.microsoft.com/en-us/library/ms227994.aspx) – sq33G

答えて

4

一般的に、この情報が自動的にキャッシュされません。

したがって、Page_Initイベントハンドラを使用して、サーバーへの要求ごとにコントロールに渡す必要があります。

パフォーマンスを向上させるために、データをSession/Cache 変数に保存することができます。DevExpress社KB以下参照チェックのために

あなたの質問とKBについて:すべてのポストバック

上の複数のデータベースのヒットを避けるために
rebinding gridview at each postback
Bind a grid to a DataTable via code.
Why might paging (sorting, grouping, filtering) not work in the ASPxGridView?

//セッションでのキャッシュのDataTableを

DataTable GetTable() { //You can store a DataTable in the session state DataTable table = Session["Table"] as DataTable; if (table == null) { table = new DataTable(); table.Columns.Add("id", typeof(int)); table.Columns.Add("data", typeof(String)); for (int n = 0; n < 100; n++) { table.Rows.Add(n, "row" + n.ToString()); } Session["Table"] = table; } //Otherwise you have to create a DataTable instance on every request: //DataTable table = new DataTable(); //table.Columns.Add("id", typeof(int)); //table.Columns.Add("data", typeof(String)); //for(int n = 0; n < 100; n++) { // table.Rows.Add(n, "row" + n.ToString()); //} return table; } 
DevExpress社のGridViewコントロールのパフォーマンスを向上させるために参考リンク:
Default grid data binding behavior is unworkable for large data sets
ASPxGridView.DataSourceForceStandardPaging Property
ASPxGridView - How to implement caching using the SqlCacheDependency or SqlDependency classes
Best Solution for ASPxGridView with Custom DataTable objects
Data caching on the client side
How To Cache Rows In DevExpress ASP.NET GridView
Performance issue in GridView when using paging & master detail view
Speed up your page loads with a lighter ViewState
Data Loading times and custom record loading

+0

美しい解決策。どうもありがとうございました! –

+1

Datatableに5.000以上の行が含まれている場合はどうなりますか?それはセッションでそれを保存するための良いpraticeですか? –

0

使用ViewStateの

ステップ1:

GridView1.DataSource = ds; 
ViewState["itemsetPending"] = ds; 
GridView1.DataBind(); 

ステップ2:

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) 
{ 
    DataSet m_DataTable = (DataSet)ViewState["itemsetPending"]; 

    if (m_DataTable != null) 
    { 
     DataView m_dataview = new DataView(m_DataTable.Tables[0]); 

     if (Convert.ToInt32(ViewState["m_sort"]) == 0) 
     { 
      m_dataview.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(SortDirection.Descending); 
      ViewState["m_sort"] = 1; 
     } 
     else 
     { 
      m_dataview.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection); 
      ViewState["m_sort"] = 0; 
     } 

     GridView1.DataSource = m_dataview; 
     GridView1.DataBind(); 
    } 
} 

ここでは、データセットに保存手順からのデータを記入Mとに割り当てますViewState.Justそれを試してみてください。あなたは、実行時にASPxGridViewWebChartControlデータを更新する際に

private string ConvertSortDirectionToSql(SortDirection sortDirection) 
{ 
    string newSortDirection = String.Empty; 

    switch (sortDirection) 
    { 
     case SortDirection.Ascending: 
      newSortDirection = "ASC"; 
      break; 

     case SortDirection.Descending: 
      newSortDirection = "DESC"; 
      break; 
    } 

    return newSortDirection; 
} 
1

AfterPerformCallbackを使用できます。

protected void gridSchedule_AfterPerformCallback(object sender, 
     DevExpress.Web.ASPxGridView.ASPxGridViewAfterPerformCallbackEventArgs e) 
{ 
    LoadGrid(gridSchedule); 
} 
関連する問題