Kentico unipager not working

asked on July 6, 2021 14:33

I have a custom data source bound to the repeater, and the repeater is bound to the pager element. Right now when I click on any page 0 rows are returned. I can't seem to figure out why. What's the best way to debug issues with pager? Also where does unipager generate SQL, it would be helpful if I could check that to see what it generates?

Initially on page load I am setting up the pager:

            pagerElem.PageControl = repeater.ID;

            pagerElem.PageSize = PageSize;
            pagerElem.GroupSize = GroupSize;
            pagerElem.QueryStringKey = QueryStringKey;
            pagerElem.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically;
            pagerElem.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
            pagerElem.HidePagerForSinglePage = HidePagerForSinglePage;
            pagerElem.Enabled = EnablePaging;
            pagerElem.PagerMode = UniPagerMode.PostBack;

And I have added it to the ascx file.

   <div class="Pager">
        <cms:UniPager ID="pagerElem" runat="server" />
    </div>

Correct Answer

David te Kloese answered on July 6, 2021 15:36

Since you post code of the pager is either the pager or the repeater custom code?

Most likely the datasource on the pager is not properly set, or to late in the page life cycle.

0 votesVote for this answer Unmark Correct answer

Recent Answers


answered on July 6, 2021 15:53 (last edited on March 28, 2024 05:44)

I have a custom data source providing custom query which is binding to the basic repeater on the initial page load, not on each postback. I assumed that there is something wrong with the pager and my custom datasource but I don't know how to approach it or debug.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on July 6, 2021 15:57

Is the repeater itself showing the correct first page data?

is the number of items per page set correctly?

You could just open the web part code and start debugging in Visual Studio

0 votesVote for this answer Mark as a Correct answer

answered on July 6, 2021 16:17 (last edited on March 28, 2024 05:44)

I forgot to mention one crucial issue, I can't debug, I don't have repo locally, only way of debugging is by logging stuff with EventLogger..

And yes, repeater is showing the first page data, and number of items is set correctly.

Is there a way to get SQL generated when navigating other pages? I could log that and check whats in there.

Here is my SetupControl method:

 protected void SetupControl()
{

    if (!StopProcessing)
    {
        headerControl.HeaderClick += SortButtonClicked;

        repeater.DataBindByDefault = false;
        pagerElem.PageControl = repeater.ID;

        // Init data properties.
        filter.InitDataProperties(source);
        filter.OnFilterChanged += filter_OnFilterChanged;
        source.OnFilterChanged += filter_OnFilterChanged;

        // Basic control properties
        repeater.HideControlForZeroRows = HideControlForZeroRows;
        repeater.ZeroRowsText = ZeroRowsText;

        // Data source properties
        source.FilterName = filter.ID;
        source.CacheItemName = CacheItemName;
        source.CacheDependencies = CacheDependencies;
        source.CacheMinutes = 0;

        // UniPager properties
        pagerElem.PageSize = PageSize;
        pagerElem.GroupSize = GroupSize;
        pagerElem.QueryStringKey = QueryStringKey;
        pagerElem.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically;
        pagerElem.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
        pagerElem.HidePagerForSinglePage = HidePagerForSinglePage;
        pagerElem.Enabled = EnablePaging;
        pagerElem.PagerMode = UniPagerMode.PostBack;

        #region "UniPager template properties"

        #endregion
    }
    // Connects repeater with data source. Setup control happens before sort, bind data is done and no sorting.
    if (!RequestHelper.IsPostBack())
    {
        InitHeader();
        BindTheData();
    }
}

And bind the data function:

private void BindTheData()
{
    var customDataSource = source.GetInfoDataSet();

    if (infoDataSet.Tables[0].Rows.Count == 0)
    {
        return;
    }

    repeater.DataSource = infoDataSet;
    repeater.DataBind();
}

Edit: P.S: You were right, pager was set too early in the life cycle, repeater was bound to the data source after the pager was configured.I just moved data bind at the beggining of the page load. And apparently repeater needs to be rebound on each postback which makes perferct sense, database needs to be contacted each time, as each request for a new page generates a postback. It really makes it that much difficult when you can't debug.

Now I wonder, how could I condition that DataBind to be called on postback, but not on each postback, only when unipager needs to fetch data for another page.

Edit: Created event handler for page change events, there I'm fetching the data.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.