3

I have a ListView that I am paging with a DataPager. I would like to set the initial page of the pager on Page_Load. I have tried the DataPager.SetPageProperties method but it's not doing what I need. Here's how I'm calling this method:

dataPager.SetPageProperties(3, dataPager.TotalRowCount, false);

The line above trims the datasource to start at the third item and paging still starts at 1. This is not what I want. I want to keep the entire list of items and just jump to a specific page in the list.

Is there another Property and/or method of a DataPager and/or ListView that I should use?

Any help will be greatly appreciated.

Thanks!

Mark Ursino
  • 31,209
  • 11
  • 51
  • 83
DougCouto
  • 530
  • 1
  • 3
  • 18
  • The methods described on this page seem to work: http://leedumond.com/blog/resetting-the-page-index-in-a-listview/ – samiz Jul 20 '10 at 18:03

2 Answers2

5

Try this. Not tested.

--edited--

dataPager.SetPageProperties( 
    (3 * dataPager.PageSize, 
    dataPager.MaximumRows, 
    false
);
Raj Kaimal
  • 8,304
  • 27
  • 18
  • Thanks for the suggestion. Unfortunately, it didn't work. I assumed you meant dataPager by "this.Pager" because the line you provided generated a runtime error. So I replaced "this.Pager" with dataPager but I got a blank page with no ListView items or paging elements. Thanks anyways! – DougCouto Apr 23 '10 at 14:06
  • Yes, I have edited it. What are the values of datapager.PageSize and dataPager.MaximumRows? – Raj Kaimal Apr 23 '10 at 14:40
  • I had a differnt challenge, but your hint helped me a lot. You made my day! – Thomas Krojer Feb 26 '15 at 13:56
1

If you're binding your datasource by code,you can manually set PageIndex in binding method.

grd.DataSource = something ..
grd.PageIndex = initialIndex;//where initialIndex is the index you wish to set
//you can arrange this index in your code,it's up to you actually.
grd.DataBind();

The point is before databinding you have to set new page index.
Best Regards
Myra

Myra
  • 3,646
  • 3
  • 38
  • 47