Is it possible to associate a PagedDataSource with a shared list?

I have a method for returning a group of objects in the form of a general list, which I then associate with the repeater. I want to implement paging on a relay using the PagedDataSource class, but I'm not sure if this is possible, since it does not work.

Should I change the return type of my method or can I link the PagedDataSource to a shared list?

+3
source share
2 answers

I just changed part of my code to use a generic list and it seemed to work fine, hope this helps:

, , , , PagingPanel.

, DataSource PagedDataSource (dataSource), NewsItems (searchResults), , , NewItem.

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<NewsItem> (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 < 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 && i == 0))
        {
            linkButton.Enabled = false;
            linkButton.CssClass = "SelectedPageLink";
        }

        linkButton.Text = (i + 1).ToString ();

        PagingPanel.Controls.Add (linkButton);
        if (i < (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));
}
+4
  • PagedDataSource
  • PagedDataSource , .
  • pageddatasource
+3

All Articles