Edit

Share via


DetailsView.AllowPaging Property

Definition

Gets or sets a value indicating whether the paging feature is enabled.

public:
 virtual property bool AllowPaging { bool get(); void set(bool value); };
public virtual bool AllowPaging { get; set; }
member this.AllowPaging : bool with get, set
Public Overridable Property AllowPaging As Boolean

Property Value

true to enable the paging feature; otherwise, false. The default is false.

Examples

The following code example demonstrates how to use the AllowPaging property to enable the paging capabilities of the DetailsView control.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView AllowPaging Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AllowPaging Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="Customers"
          autogeneraterows="true" 
          allowpaging="true"
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <pagersettings mode="NextPreviousFirstLast"
            firstpagetext="First"
            lastpagetext="Last"
            nextpagetext="Next"
            previouspagetext="Prev"/>
            
          <pagerstyle forecolor="White"
            backcolor="Blue"
            font-names="Arial"
            font-size="8" />   
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database. -->           
        <asp:SqlDataSource ID="Customers" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthwindConnectionString %>"
          SelectCommand="SELECT [CompanyName], [ContactName], 
             [CustomerID] FROM [Customers]">
        </asp:SqlDataSource>
            
      </form>
  </body>
</html>
<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView AllowPaging Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AllowPaging Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="Customers"
          autogeneraterows="true" 
          allowpaging="true"
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <pagersettings mode="NextPreviousFirstLast"
            firstpagetext="First"
            lastpagetext="Last"
            nextpagetext="Next"
            previouspagetext="Prev"/>
            
          <pagerstyle forecolor="White"
            backcolor="Blue"
            font-names="Arial"
            font-size="8" />   
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database. -->           
        <asp:SqlDataSource ID="Customers" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthwindConnectionString %>"
          SelectCommand="SELECT [CompanyName], [ContactName], 
             [CustomerID] FROM [Customers]">
        </asp:SqlDataSource>
            
      </form>
  </body>
</html>

Remarks

The DetailsView control has built-in paging capabilities, which allow a user to navigate to a different record in the data source.

The DetailsView control can perform both user interface (UI) and data source paging. The UI paging feature can be used with any data source object that supports the System.Collections.ICollection interface. For each paging operation, the DetailsView control queries the data source for the entire data collection and selects the row to display, essentially discarding the remaining data.

If a data source implements DataSourceView and the CanPage property returns true, the DetailsView control will use data source paging instead of UI paging. In this case, the DetailsView control will query for only the row needed for each paging operation. Thus, data source paging is more efficient than UI paging. Only the ObjectDataSourceView object supports data source paging without modification.

To enable the paging feature, set the AllowPaging property to true. You can determine the total number of items in the underlying data source by using the PageCount property. To determine the index of the currently displayed item, use the PageIndex property.

When paging is enabled, an additional row called the pager row is automatically displayed in the DetailsView control. The pager row contains the page navigation controls and can be displayed at the top, bottom, or both the top and bottom of the control. The pager row has two built-in pager display modes: numbered pages and next and previous page links (default). The numbered pages mode displays links for the individual pages, allowing the user to navigate to a specific page. The next and previous links mode displays controls that allow the user to navigate to the next or the previous page.

Note

The DetailsView control automatically hides the pager row when the data source contains fewer than two records.

You can control the settings of the pager row (such as the pager display mode, the number of page links to display at a time, and the pager control's text label) by using the PagerSettings property. To control the appearance of the pager row (including its background color, font color, and position), use the PagerStyle property. The DetailsView control also allows you to define a custom template for the pager row. For more information on creating a custom pager row template, see PagerTemplate.

The DetailsView control provides several events that you can use to perform a custom action when paging occurs. The following table lists the available events.

Event Description
PageIndexChanged Occurs when one of the pager buttons is clicked, but after the DetailsView control handles the paging operation. This event is commonly used when you need to perform a task after the user navigates to a different record in the control.
PageIndexChanging Occurs when one of the pager buttons is clicked, but before the DetailsView control handles the paging operation. This event is often used to cancel the paging operation.

The value of AllowPaging is stored in view state.

Applies to

See also