data pager
TRANSCRIPT
-
7/31/2019 Data Pager
1/4
The ListView is a hybrid control between a DataGrid and Repeater that combines the
templating of the Repeater and the editing features of the data grid. The ListView is similar to
the Repeater in that it allows one to define the layout of the HTML rendered to the browser,
using various templates:
1.
LayoutTemplate - The root template that defines a container object, such as a table, div,or span element, that will contain the content defined in the ItemTemplate or
GroupTemplate template. It might also contain a DataPager object.
2. ItemTemplate - Defines the data-bound content to display for individual items.3. ItemSeparatorTemplate - Defines the content to render between individual items.4. GroupTemplate - Defines a container object, such as a table row (tr), div, or span
element, that will contain the content defined in the ItemTemplate and
EmptyItemTemplate templates. The number of items that are displayed in a group is
specified by the GroupItemCount property.
5. GroupSeparatorTemplate - Defines the content to render between groups of items.6. EmptyItemTemplate - Defines the content to render for an empty item when a
GroupTemplate template is used. For example, if the GroupItemCount property is set to
5, and the total number of items returned from the data source is 8, the last group of
data displayed by the ListView control will contain three items as specified by the
ItemTemplate template, and two items as specified by the EmptyItemTemplate
template.
7. EmptyDataTemplate - Defines the content to render if the data source returns no data.8. SelectedItemTemplate - Defines the content to render for the selected data item to
differentiate the selected item from other items.
9. AlternatingItemTemplate - Defines the content to render for alternating items to makeit easier to distinguish between consecutive items.
10.EditItemTemplate - Defines the content to render when an item is being edited. TheEditItemTemplate template is rendered in place of the ItemTemplate template for the
data item that is being edited.
11.InsertItemTemplate - Defines the content to render to insert an item. TheInsertItemTemplate template is rendered in place of an ItemTemplate template at
either the start or at the end of the items that are displayed by the ListView control. You
can specify where the InsertItemTemplate template is rendered by using the
InsertItemPosition property of the ListView control.
The ListView doesn't support paging, so theDataPagerserves as an external control to provide
paging features. The advantage of a separate control is that it gives more control about what
the pager looks like and where it can be placed on the page. The DataPager class is used to page
http://msdn.microsoft.com/en-us/library/cc295263.aspxhttp://msdn.microsoft.com/en-us/library/cc295263.aspxhttp://msdn.microsoft.com/en-us/library/cc295263.aspxhttp://msdn.microsoft.com/en-us/library/cc295263.aspx -
7/31/2019 Data Pager
2/4
data and to display navigation controls for data-bound controls that implement the
IPageableItemContainer interface.
DataPager control can be associated with the data-bound control by using the PagedControlID
property. Alternatively, by putting the DataPager control inside the data-bound control
hierarchy. For example, in the ListView control, DataPager control can be kept inside theListView-LayoutTemplate.
The number of items that are displayed for each page of data can be customized by changing
the PageSize property. The way a page is submitted to the server can be changed by setting the
QueryStringField property.
Pager Fields
In order for the DataPager control to display navigation controls, pager fields are added to the
control that are derived from the DataPagerField class.
Pager field type DescriptionNextPreviousPagerField Enables users to navigate through pages one page at a time, or to
jump to the first or last page.NumericPagerField Enables users to select a page by page number.TemplatePagerField Enables you to create a custom paging UI.
To declaratively add pager fields to the DataPager control, add a Fields element to the
DataPager control. You can then add the pager fields to the Fields element. The pager fields areadded to the Fields collection in the order that they appear in the Fields element. The Fields
collection enables you to programmatically manage the pager fields in the DataPager control.
Page Properties
The following table lists read-only properties of the DataPager control that specify
characteristics of the page of data. These properties are usually used for binding expressions in
the TemplatePagerField object.
Property DescriptionMaximumRows The maximum number of records that are displayed for each page of data.StartRowIndex The index of the first record that is displayed on a page of data.TotalRowCount The total number of records that are available in the underlying data
source.
-
7/31/2019 Data Pager
3/4
Let us create a small example using the Northwind database.
Create the Layout Template that will represent that how ListView will look
Product Name
Quantity/Unit
Unit Price
Create a ListView with ItemTemplate containing the fields that you want to show from Products
table
Put the DataPager inside the ListView Layout Template or anywhere on that page. Here I am
putting the DataPager inside the Layout Template
-
7/31/2019 Data Pager
4/4
Url="~/Images/Paging/PreviousHover.gif" ShowLastPageButton="false"ShowNextP
ageButton="false"/>