Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've just modified some of my code to use a generic list and seems to have worked fine, hope this helps:</p> <p>Note that this entire method can be called with or without a page number to automatically set the page, it also builds a paging control inside of a panel calling PagingPanel.</p> <p>The line that sets the DataSource on the PagedDataSource instance (dataSource) did take an array of NewsItems (searchResults), I've updated it to consume a List that's created using the NewItem array.</p> <pre><code>void PopulateNewsItems (int? pageNo) { var model = ModelFactory.GetNewsModel (); var searchResults = model.GetNewsItems (); var dataSource = new PagedDataSource (); // CHANGED THE ARRAY OF NEWSITEMS INTO A GENERIC LIST OF NEWSITEMS. dataSource.DataSource = new List&lt;NewsItem&gt; (searchResults); dataSource.AllowPaging = true; var pageSizeFromConfig = ConfigurationManager.AppSettings["NewsItemsPageCount"]; var pageSize = 10; int.TryParse (pageSizeFromConfig, out pageSize); dataSource.PageSize = pageSize; dataSource.CurrentPageIndex = pageNo ?? 0; PagingPanel.Controls.Clear (); for (var i = 0; i &lt; dataSource.PageCount; i++) { var linkButton = new LinkButton (); linkButton.CommandArgument = i.ToString (); linkButton.CommandName = "PageNo"; linkButton.Command += NavigationCommand; linkButton.ID = string.Format ("PageNo{0}LinkButton", i); if (pageNo == i || (pageNo == null &amp;&amp; i == 0)) { linkButton.Enabled = false; linkButton.CssClass = "SelectedPageLink"; } linkButton.Text = (i + 1).ToString (); PagingPanel.Controls.Add (linkButton); if (i &lt; (dataSource.PageCount - 1)) PagingPanel.Controls.Add (new LiteralControl ("|")); } NewsRepeater.DataSource = dataSource; NewsRepeater.DataBind (); } void NavigationCommand (object sender, CommandEventArgs e) { PopulateNewsItems (int.Parse ((string)e.CommandArgument)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload