我正在使用 Umbraco CMS 并尝试制作下一个和上一个按钮来滚动页面/节点的集合。我已设法使总页数正确,但 CurrentPageIndex 始终显示为 0,如何获取页面在我的 PagedDataSource 创建的列表中的位置的 CurrentPageIndex 并增加/减少它以移动到下一个页?
到目前为止我得到的代码是:
ASP.NET:
<div class="detail-paging">
<div class="list-paging-control">
<p><asp:HyperLink runat="server" id="lnkFirstPage"><<</asp:HyperLink></p>
<p><asp:HyperLink runat="server" id="lnkPrev" OnServerClick="lnkPrev_Click"><</asp:HyperLink></p>
</div>
<div class="list-paging-numbers">
<p><asp:Label runat="server" ID="lblCurrentScroll"></asp:Label></p>
</div>
<div class="list-paging-control left-marker">
<p><asp:HyperLink runat="server" id="lnkNext" OnServerClick="lnkNext_Click">></asp:HyperLink></p>
<p><asp:HyperLink runat="server" id="lnkLastPage">>></asp:HyperLink></p>
</div>
<div class="list-paging-text">
<p><asp:HyperLink runat="server" ID="lnkViewAll" OnClick="ViewAll_Click">View All</asp:HyperLink></p>
</div>
C#:
private PagedDataSource paging;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DoDataBind();
}
}
public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}
//ALL CODE THAT BINDS DATA FROM UMBRACO
public void DoDataBind()
{
//Get the parent node.
Node parent = new Node(1152);
//Get all the BrandsDetailPage children and order alphabetically.
IEnumerable<INode> nodes = HelperMethods.GetChildrenOfType(parent, "BrandsDetailPage", true, true).OrderBy(n => n.Name);
//Pagination
paging = new PagedDataSource()
{
AllowPaging = true,
DataSource = nodes.ToList(),
CurrentPageIndex = PageNumber,
PageSize = 1
};
//pageNumber = paging.CurrentPageIndex;
CreateNavigation();
}
//ALL CODE THAT BINDS DATA FROM UMBRACO
//PAGINATION
public void CreateNavigation()
{
lblCurrentScroll.Text = PageNumber.ToString();
lblCurrentScroll.Text += " of ";
lblCurrentScroll.Text += paging.PageCount;
Node node = new Node(1153);
string nodeUrl = node.Url;
lnkViewAll.NavigateUrl = string.Format("{0}?page=All", nodeUrl);
}
protected void lnkPrev_Click(object sender, EventArgs e)
{
PageNumber--;
DoDataBind();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
PageNumber++;
DoDataBind();
}