Asp.Net: DataPager problem with Listview

When using the Datapager with a ListView I had the following problem. When clicking a paging button for the first time nothing happens.But when I click a button the second time, then the page from the first click loads.

I search the internet for a solution and found that you need to add some code to the OnPagePropertiesChanging event of the list view to reload the DataPager.

The following code is the solution to my problem. Including a fix that the data doesn’t get loaded two times.

[code language=’c#’]
private List productList;

protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)

private void fillGrid()
    if(productList == null)
        productList = getproducts();
    ListView1.DataSource = productList;

public List getproducts()
    using (AdventureWrksDataContext db = new AdventureWrksDataContext())
        return db.Products.ToList();

protected void lvproducts_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);


You can download the solution ( (83.05 kb))



2 Replies to “Asp.Net: DataPager problem with Listview”

  1. Ohhh 🙂 God Bless you, man. I was trying to fix that bug for a couple of hours. Finally I made it – thanks to your post 🙂

    Thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *