ASPX templates
Version 6.x > ASPX templates > Pagination with a CMSRepeater whiles databinding from code behind View modes: 
User avatar
Member
Member
maaizle-yahoo - 11/25/2012 11:34:21 AM
   
Pagination with a CMSRepeater whiles databinding from code behind
Hi I have a CMSRepeater that I am trying to bind to a custom dataset from the page load event in the code behind file. Here is the repeater in question.

<cms:CMSRepeater ID="rptCandidates" DelayedLoading="true" runat="server" OnItemCommand="_postsRepeater_ItemCommand"
DataBindByDefault="false" EnablePaging="true" PageSize="10"
PagerControl-BackNextLinkSeparator="|" PagerControl-BackText="Previous" PagerControl-NextText="Next"
PagerControl-PageNumbersSeparator="|" PagerControl-PageSize="10" PagerControl-ResultsFormat="{0}-{1} Candidates of {2}"
PagerControl-PagerNumberAreaClass="rightPagination" PagerControl-ResultsClass="leftPagination"
PagerControl-ShowFirstLast="False" PagerControl-ControlCssClass="pagination"
PagerControl-SelectedClass="selected"
PagerControl-HideOnSinglePage="True" ZeroRowsText="No candidates found." PagerControl-SliderSize="5" PagerControl-PagingMode="PostBack" PagerControl-EnableViewState="False">
<ItemTemplate>
<div id="candidate" class="candidate">
<div id="candidate-inner">
<div id="name">
<%# WoodinCampaignHelper.GetProfileUsername(Eval("ID").ToString()) %></div>
<div id="img">
<a class="que" title='<%# CampaignHelper.GetCandidateDescription(Eval("ID").ToString(),int.Parse(Eval("CompetitionID").ToString())) %>'
rel="#">
<img src='<%#CampaignHelper.GetProfilePicture(Eval("ID").ToString()) %>'
width="108px" /></a></div>
<div id="vote">
<div class="votes">
<%#CampaignHelper.GetCandidateVoteCount(Eval("ID").ToString(),int.Parse(Eval("CompetitionID").ToString())) %>
Vote(s)</div>
<div class="vote">
<asp:LinkButton ID="lnkVoteMe" ClientIDMode="Static" CommandArgument='<%#Eval("candidateID").ToString() %>'
runat="server" CssClass="vote_button" CommandName="VoteMe">
<div class="span">Vote</div>
</asp:LinkButton>
</div>
</div>
</div>
</div>

</ItemTemplate>
</cms:CMSRepeater>


And here is the page load event:
protected void Page_Load(object sender, EventArgs e)
{

DataSet dsCandidates = CampaignHelper.GetAllCandidatesAsDataset(CampaignHelper.GetCurrentCompetitionID());
rptCandidates.DataSource = dsCandidates;
rptCandidates.Databind();
//rptCandidates.ReloadData();

}


It works on the first page, but immediately you move to the next page the code seems to break.
As you can see I have tried the reload data as well but it doesn't seem to be working. The reason why am using a cmsrepeater is that it provides a simple way of paging the data. Is there anyway to make this work or do I have to write custom paging for the control and use an ASP repeater.

A good working example will be appreciated. Thanks in advance.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/27/2012 2:25:42 AM
   
RE:Pagination with a CMSRepeater whiles databinding from code behind
Hi,

Have you tried using the basic repeater and the approach mentioned in data source web parts? And connect the universal pager to it? You can also connect the universal pager to the current control.

However, have you tried to debug your code? Does it make through the IsPostback check on the second time? If not, have you tried to disable the postback checking?

Best regards,
Juraj Ondrus