Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [265]

By Root 5364 0
interface.

PageSize

Gets and sets the size of the page. The default value is 10.

QueryStringField

The name of the query string field for the current page index. The pager uses the query string when this property is set.

StartRowIndex

Gets the index of the first item in the data source to display.

TotalRowCount

Gets the total number of rows to page through.

Only a few of these properties can be set declaratively. They are Fields, PagedControlID, PageSize, and QueryStringField. The other properties are read-only and owe their value to the paged control and the size of the bound data source.

Using the DataPager Control


The following code snippet shows the typical code you use to embed a data pager in an ASP.NET page that hosts a ListView control:

PagedControlID="ListView1" PageSize="4">

The DataPager control heralds a new model for paging data-bound controls that is quite a bit different from the model employed by GridView controls. The user interface for paging is not part of the control, but it can be placed anywhere in the page and even driven through the query string.

The DataPager control is linked to the data-bound control being paged and lets this control know about the user selection. Subsequently, the paged control adjusts its row properties and passes the information back to the data pager. Figure 11-12 shows a data pager in action.

Figure 11-12. A data pager in action—the pager can be placed anywhere in the page.

Configuring the Data Pager Fields


The user interface of the data pager control is largely customizable. You do that through the Fields property—a collection of DataPagerField objects. The property allows you to add multiple pagers of different styles. Table 11-8 lists the various options you have.

Table 11-8. Types of Data Pagers

Type

Description

NextPreviousPagerField

Displays a fully customizable Next/Previous user interface for the pager. You can use images or text for Next/Previous buttons and also add a First/Last pair of buttons.

NumericPagerField

Displays a fully customizable list of numeric links, one for each page. The number of pages is calculated on the page size and the total number of bound rows.

TemplatePagerField

Allows you to use a user-defined template for the pager.

All classes in Table 11-8 inherit from the same common class—DataPagerField. If you’re OK with the default user interface of the pagers, you don’t need to set any of the pager’s properties. The following markup, therefore, is perfectly functional:

Pager fields, though, have a number of visual properties to set the CSS style of buttons, the companion text, or perhaps the images to use instead of text.

Pageable Containers


As mentioned, the data pager control doesn’t handle data itself. Rather, the control is the manager of the paging user interface. For this reason, it needs to communicate with the paged control. Whenever a button in the pager is clicked to move to a given page, the pager control fires a message to the paged control and has it refresh the user interface properly.

Not all data-bound controls can be paged using a data pager. In ASP.NET, this privilege is limited to controls that implement the IPageableItemContainer interface. Currently, the sole control to support this interface is the ListView control. You can create your own custom controls to implement the interface, however. Here’s the definition of the interface:

public interface IPageableItemContainer

{

// Events

event EventHandler TotalRowCountAvailable;

// Methods

void SetPageProperties(int startRowIndex, int maximumRows, bool databind);

// Properties

int MaximumRows { get; }

int StartRowIndex { get; }

}

The PagedControlID property on the DataPager control defines the linked data-bound control. Whenever the pager is acted on, it invokes the SetPageProperties method on the paged control

Return Main Page Previous Page Next Page

®Online Book Reader