1)アプリケーションは、結果のセット全体またはページ化されたセットのみを取得するために、ページインデックスが変更されるたびにDBに接続する必要はありません。
結果をキャッシュする必要があります。例えば:
例:
キャッシングアプローチ1
<asp:SqlDataSource runat="server" ID="sdsd"
SelectCommand="select * from jobs"
SelectCommandType="Text"
DataSourceMode="DataSet"
ConnectionString="<%$ConnectionStrings: PUBSConnectionString %>"
CacheDuration="30"
EnableCaching="true"
>
</asp:SqlDataSource>
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" DataSourceID="sdsd" DataTextField="job_desc" DataValueField="job_id">
</asp:DropDownList>
キャッシングアプローチ2
結果はいつでもコードにキャッシュできます。
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
IEnumerable<employee> res = Enumerable.Empty<employee>();
if (this.Cache["emp"] == null)
{
res = this.GetEmployeesFromDatabase();
this.Cache["emp"] = res;
}
else
{
res = this.GetEmployeesFromCache();
}
this.grv.DataSource = res;
this.grv.DataBind();
}
}
protected IEnumerable<employee> GetEmployeesFromDatabase()
{
// go to your database to get the objects
return Enumerable.Empty<employee>();
}
protected IEnumerable<employee> GetEmployeesFromCache()
{
return this.Cache["emp"] as IEnumerable<employee>;
}
キャッシュ結果に並べ替え機能を追加するには、返されるオブジェクトがまたはである必要があることに注意DataSet
してください。DataTable
2)結果をビューステートまたはセッションに保存したくない
ここでも、キャッシュを使用する必要があります
asp.netでそれを行う方法はありますか、またはこのシナリオではjQueryを検討する必要があります。
jQuery(それ自体)が要件にどのように役立つかわかりません。つまり、AJAX投稿を使用すると、現在のページの知覚パフォーマンスが向上しますが、データベースへの接続には役立ちません。キャッシングを使用しない限り