是的,據我所知,如果您沒有將緩存設置爲true,它將執行每個數據綁定調用的查詢。
就個人而言,您可能會更好地查詢結果,然後在ItemDataBound事件中手動綁定它,而不是用SQL數據源打擾,但是,如果您當前的擔心正在通過當前配置緩存應該會有很大幫助!
更新
添加了以下對評論做出迴應。你可以聲明一個頁面級別的變量來存放數據表,然後在項目數據綁定事件中你可以使用它來進行綁定,如果是CS,就可以使用它。這只是一個部分的例子......只是爲了讓這個想法貫穿始終。
partial class MyPage
{
private DataTable _ddlData;
protected void Page_Load(object sender, EventArgs e)
{
//Logic to fill _ddlData and then bind the repeater goes here
}
protected void Grid_ItemDataBound() //I forgot the proper parameters here
{
//Properly check for e.item.itemtype = Item or Alt item
DropDownList oList = (DropDownList)e.item.findcontrol("ddlItems"); //lookup for your item
oList.DataSource = _ddlData;
oList.DataBind();
}
}
您認爲存儲數據表結果的最佳存儲機制是什麼? page_load是否在所有項目數據綁定事件之前運行,以便我可以在頁面加載中查詢它們並將其粘貼在視圖狀態或其他內容中? – 2008-12-02 19:35:02