How do I use a DataPager with Server Side Paging?

前端 未结 3 1460
灰色年华
灰色年华 2020-12-30 05:46

I\'m trying to use a DataPager to do Server Side paging. Here is my code



        
3条回答
  •  庸人自扰
    2020-12-30 06:23

    Exactly needed what you did - SQL server paging utilizing listview, datapager and linq data source. As you say TotalRowCount is readonly. There is also SetPageProperties method that can be used to set the total row count but that also didn't work for me.

    However I managed to trick it this way. I have a dummy hidden listview with empty item template. The pager will be pointing at this dummy listview rather than the original listview. Then we need to bind the dummy listview to a dummy collection with the same number of items as in the original data source. This will ensure rendering the pager correctly. Here is the markup.

    
    
        
    
    
    
    
    
    
    
    ...
    

    and code behind

            var datasourceQuery = context.Properties.OrderBy(x => x.PropertyID).Skip(pdPagerBottom.StartRowIndex).Take(pdPagerBottom.PageSize);
    
            this.lvPropertyList.DataSource = datasourceQuery;
            this.lvPropertyList.DataBind();
    
            this.lvDummy.DataSource = new List(Enumerable.Range(0, context.Properties.Count()));
            this.lvDummy.DataBind();
    

    Tested it with 100k records. Works a treat.

提交回复
热议问题