Associated with dropdown in repeater item template using sql data source

We are having performance issues on the page and I wanted to ask about it. If I have a repeater and in the repeater item table I have a dropdown associated with a sql data source, will this select method be called once for each item, even if the same result is returned every time? If so, as a quick fix, would allow caching to be set to true and have the specified cache duration ensure that this request is only executed once per page lifecycle? I know I should be using an object datasource, but I want to try and fix it quickly. Thanks in advance.

0


source to share


1 answer


Yes, as far as I know, if you don't have the cache set to true, it will execute the request for every data binding call.

Personally, you might be better off querying the results and then manually binding them to the ItemDataBound event rather than even bothering with the SQL data source, however, if your current problem is with your current configuration, caching should help a lot!

Update



Added the following in response to the comment.

Page_Load is executed first in the chain of command, you can declare a page level variable to store the data, then inside the item's data binding event, you can use it to bind, something like this if it is CS. This is just a partial example ... just to get the idea.

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();
    }
}

      

0


source







All Articles