Data List and Pagination
Below code uses the Repeater and ListTitle components to display a table of records to end users.
<aspx:AspxPage runat="server" Id="PaginationPage" title="Account Pagination">
<body>
<aspx:AlphabeticFilter ID="filter" runat="server" TabIndex="5"/>
<div class="table-responsive table-border-outer">
<table class="table table-striped">
<thead>
<tr>
<th><aspx:ListTitle runat='server' value='{!$entity.Force__Account.Name}' sortExpression="Name" DefaultWithSortDirection="Descending" /></th>
<th><aspx:ListTitle runat='server' value='{!$entity.Force__Account.OwnerId}' sortExpression="Owner.Name"/></th>
<th><aspx:ListTitle runat='server' value='{!$entity.Force__Account.CreatedById}' sortExpression="CreatedBy.Name"/></th>
</tr>
</thead>
<tbody>
<aspx:Repeater runat='server' value='{!Model}' var='item'>
<body>
<tr>
<td>
<aspx:Field runat='server' value='{!item.Name}'/>
</td>
<td>
<a class="mng-sys-link" href="/{!item.OwnerId}">{!item.Owner.Name}</a>
</td>
<td>
<a class="mng-sys-link" href="/{!item.CreatedById}">{!item.CreatedBy.Name}</a>
</td>
</tr>
</body>
<empty>
<tr>
<td colspan="3">
There are no records to display.
</td>
</tr>
</empty>
</aspx:Repeater>
</tbody>
</table>
</div>
<aspx:Pagination runat="server"
PageSize="<%# DataBag.PageSize %>"
TotalRecords="<%# DataBag.TotalRows %>"
RecordCount="<%# (Model != null) ? (Model as IList).Count : 0 %>"
ShowPageNumbers="true"
ShowPageSizeControl="true"
CssClass="active-border rounded-bottom panel-footer" />
</body>
</aspx:AspxPage>
Controller Code:
public class PaginationController : AspxController
{
public override ActionResponse Index()
{
// Reads the URL parameters for sorting, sort direction & pagination
var listOptions = new ListViewOptions("Name", ListSortDirection.Descending, 20);
// ApplyListViewOptions will apply all above settings to the query
var results = Database.Query<Force__Account>()
.Include(a => a.Owner, f => new { f.Name })
.Include(a => a.CreatedBy, f => new { f.Name })
.ApplyListViewOptions(listOptions)
.ToQueryResult();
// This passes page size and total number of records to the pagination control
DataBag.PageSize = listOptions.PageSize;
DataBag.TotalRows = results.Count;
return View(results.Records);
}
}