views:

272

answers:

1

I've created links in the listview which is attached to the datapager. When a user clicks a link they see content to the left but the datapager changes from any page to page 1.

+1  A: 

You need to add a querystring field indicating the page number to each of your links. Then you need to set the querystringfield attribute of the datapager control equal to the name of that querystring field.

For example:

   <asp:DataPager ID="dpItems" runat="server" PagedControlID="lvItems" PageSize="10" QueryStringField="pageNumber">

From MSDN: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datapager.querystringfield.aspx

If you want to do the paging math yourself, you can also set the StartRowIndex property at runtime. You can't, however, set the page directly. Eg., if you are displaying 10 records per page, and you want to display the second page, then you would set myDataPager.StartRowIndex = 20 in your runtime code.

Alternatively, the datapager can handle this math automatically and generate the paging controls when you set up the datapager's fields and set the querystringfield value. You can either have it use Next/Previous buttons, numeric page links, or define your own paging controls in a template.

If defining your own paging controls, then your could look like this:

Then in the lvItems's OnDataBound event, grab the Placeholder with (Placeholder)lvItems.FindControl("phPageNumberButtons") and then add your controls to the placeholder.

Also, make sure that you define PagedControlID equal to your listview's ID

Here's a link to the MSDN article where you can get more information on the fields: msdn.microsoft.com/en-us/library/

CuriousCoder
insanepaul
I just need to know what to do to set the page number at runtime
insanepaul
Were you able to figure this out?
CuriousCoder