Unable to get UniPager working with CMSRepeater control bound to custom data source

Tom Troughton asked on September 2, 2015 18:06

I have a test web part user control with the following markup:

<cms:CMSRepeater ID="CMSRepeater1" runat="server" Path="/Our-work/Countries/%" ClassNames="Custom.CountryPage" DelayedLoading="true" OrderBy="NodeLevel, NodeOrder">
     <ItemTemplate>
        <%# HTMLHelper.HTMLEncode(Convert.ToString(Eval("NodeAliasPath"))) %>
    </ItemTemplate>
    <SeparatorTemplate>
        <br />
    </SeparatorTemplate>
</cms:CMSRepeater>

<cms:CMSRepeater ID="CMSRepeater2" runat="server" DelayedLoading="true">
    <ItemTemplate>
        <%# HTMLHelper.HTMLEncode(Convert.ToString(Eval("NodeAliasPath"))) %>
    </ItemTemplate>
    <SeparatorTemplate>
        <br />
    </SeparatorTemplate>
</cms:CMSRepeater>

<cms:UniPager ID="uniPager" runat="server" PagerMode="Querystring" QueryStringKey="tp" PageControl="CMSRepeater1" PageSize="5" GroupSize="10">
    <PageNumbersTemplate>
        <a href="<%# Eval("PageURL") %>"><%# Eval("Page") %></a>
    </PageNumbersTemplate>
</cms:UniPager>

Notice here I have two repeaters. The first is configured with data source properties within the server control's properties. The pager at the bottom is associated with this first repeater using its PageControl property.

This works fine - the repeater loads a page of data and the pager displays correctly.

However, the data source I need to use is more complex than the repeater's properties allow. Therefore I need to bind my repeater to a custom data source. So, I change the UniPager's PageControl property to CMSRepeater2 and in my code behind add the following:

    protected void Page_Load(object sender, EventArgs e)
    {
        var pds = new PagedDataSource();
        pds.DataSource = GetNodes();
        pds.AllowPaging = true;
        pds.PageSize = 5;

        CMSRepeater2.DataSource = pds;
    }

The GetNodes() method simply returns a large list of TreeNode objects. When I load this web part what I now see is the expected number of items listed by my repeater (5, as defined by PageSize), but the UniPager control is no longer displaying.

I assumed this must be because my PagedDataSource object is defining its own PageSize, but if I don't define this property I just 10 items in the repeater (presumably a default) and still no pager.

Can anyone help me understand how to wire up a UniPager to a CMSRepeater in this way?

Recent Answers


Roman Hutnyk answered on September 2, 2015 22:24 (last edited on September 2, 2015 22:24)

Have you tried development of a regular data source web part, not paged one?

0 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on September 3, 2015 11:24

Hi Roman, can you provide more detail?

I've tried instead to declare a SQLDataSource control on the web part...

<cms:SQLDataSource id="testDataSource" runat="server" />

...then change my code behind to this:

testDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString;
testDataSource.QueryText = "SELECT * FROM [dbo].[MYTABLE]";
testDataSource.QueryType = CMS.DataEngine.QueryTypeEnum.SQLQuery;
testDataSource.LoadData(true);
testDataSource.UniPagerControl = uniPager;

CMSRepeater2.DataSource = testDataSource.DataSource;
CMSRepeater2.DataBind();

But this also just loads all records and doesn't neither obeys the UniPager settings nor displays the UniPager.

This must be a common requirement. Please can anyone explain how to create a web part with a repeater and a pager?

0 votesVote for this answer Mark as a Correct answer

Ryan Van Der Meide answered on February 17, 2016 17:15 (last edited on February 17, 2016 17:22)

I'm having the same issue. Is there a way to get this to work? I tried using a universal viewer and had the same results.

I'm using a custom data source as described here https://docs.kentico.com/display/K82/Developing+data+source+web+parts

I forgot to add that this worked fine in 7 but after the upgrade to 8.2 is is not working .

0 votesVote for this answer Mark as a Correct answer

Thai Tran answered on November 29, 2016 04:12

Sorry for the late response. For those who have the same issue, let's try to use the UniPager with the UniView control.

0 votesVote for this answer Mark as a Correct answer

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