13.3. Using the DataPager with a ListView

The ASP.NET DataPager control lets users deal with data in small chunks by stepping through it one page at a time. You can set the number of items per page and the pager appearance. The built-in navigation options are Next/Previous buttons and numeric paging. Follow these steps to add paging to this chapter's ListView sample:

  1. Open julielistview.aspx in Source view.

  2. From the Toolbox, drag a DataPager control from the Data section and drop it before the closing </form> tag.

  3. In the DataPager control's Properties window (F4), in the Fields property, click the ellipsis button (...).

    The Fields dialog box appears.

  4. In the Available Fields area, click Numeric Pager Field, click Add, and then click OK.

    The Fields dialog box closes and you return to the Properties window.

  5. Back in the Properties window, set the PagedControlID to the name of the ListView control that you want paged, usually ListView1.

  6. Set the PageSize property value to the number of items that should appear on the page at one time, such as 5.

When included in a <div> tag for style and formatting, the preceding steps create the following markup:

<div class="datapager">
    <asp:DataPager PageSize="5" ID="DataPager1"
      PagedControlID="ListView1" runat="server">
      <Fields><asp:NumericPagerField /></Fields>
    </asp:DataPager>
</div>

To position the DataPager, try this style:

.datapager { clear: both; ...

Get ASP.NET 3.5 For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.