Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

asp.net - Kentico CmsRepeater: When to call databind when DataBindByDefault="false"

I want to set DataBindByDefault to false on my repeater because otherwise it makes a call to the db which returns all data from the child nodes of the page which comes to 12MB.

I've hacked it for now and set the Path value to "." (same page only) in the code in front but it's still an extra db call.

So my plan was to set DataBindByDefault to false, assign the data from my custom query to the repeater and then call databind() as follows:

<cms:CMSRepeater ID="repItems" runat="server" Path="."/>

private void InitRepeater()
{
    var data = (DataSet)NewsProvider.GetNews(ClassNames, Path, MaxRelativeLevel, OrderBy, WhereStatement, SelectTopN, -1, -1);
    if (!DataHelper.DataSourceIsEmpty(data))
    {
        repItems.DataSource = data;
        repItems.ControlContext = ControlContext;
        repItems.EnablePaging = true;
        repItems.PageSize = PageSize;
        repItems.PagerControl.CurrentPage = 1;
        repItems.PagerControl.PageSize = PageSize;
        repItems.PagerControl.Visible = false;
        repItems.HideControlForZeroRows = true;
        repItems.TransformationName = Transformation;
        repItems.DataBind();
    }
}

InitRepeater() is called from SetupControl() which called from OnContentLoaded() and ReloadData() but nothing gets rendered.

If I try calling InitRepeater() in PreRender it renders but it ignores the paging settings.

I'm using Kentico v12.0.65


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should be using the LoadPagesIndividually property of the repeater control. If true, each page is loaded individually in case of paging.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...