DetailsView.AllowPaging 属性

定义

获取或设置一个值,该值指示是否启用分页功能。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

属性值

如果启用分页功能,则为 true;否则为 falsetrue to enable the paging feature; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例演示如何使用AllowPaging属性启用DetailsView控件的分页功能。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>

注解

DetailsView控件具有内置分页功能, 使用户可以导航到数据源中的其他记录。The DetailsView control has built-in paging capabilities, which allow a user to navigate to a different record in the data source.

DetailsView控件既可执行用户界面 (UI), 也可执行数据源分页。The DetailsView control can perform both user interface (UI) and data source paging. UI 分页功能可用于支持接口的System.Collections.ICollection任何数据源对象。The UI paging feature can be used with any data source object that supports the System.Collections.ICollection interface. 对于每个分页操作, DetailsView控件会在数据源中查询整个数据集合, 并选择要显示的行, 实质上是放弃剩余的数据。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.

DataSourceView如果数据源实现CanPage并且属性返回true, 则该DetailsView控件将使用数据源分页而不是 UI 分页。If a data source implements DataSourceView and the CanPage property returns true, the DetailsView control will use data source paging instead of UI paging. 在这种情况下DetailsView , 该控件将仅查询每个分页操作所需的行。In this case, the DetailsView control will query for only the row needed for each paging operation. 因此, 数据源分页比 UI 分页更有效。Thus, data source paging is more efficient than UI paging. ObjectDataSourceView仅对象不支持修改数据源分页。Only the ObjectDataSourceView object supports data source paging without modification.

若要启用分页功能, 请将AllowPaging属性设置true为。To enable the paging feature, set the AllowPaging property to true. 可以通过使用PageCount属性来确定基础数据源中的总项数。You can determine the total number of items in the underlying data source by using the PageCount property. 若要确定当前显示项的索引, 请使用PageIndex属性。To determine the index of the currently displayed item, use the PageIndex property.

启用分页时, 会自动在DetailsView控件中显示一个名为 "页导航行" 的附加行。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.

备注

DetailsView数据源包含的记录少于两条时, 控件将自动隐藏页导航行。The DetailsView control automatically hides the pager row when the data source contains fewer than two records.

通过使用PagerSettings属性, 可以控制页导航行的设置 (如页导航显示模式、一次显示的页链接的数目以及页导航控件的文本标签)。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. 若要控制页导航行的外观 (包括其背景色、字体颜色和位置), 请使用PagerStyle属性。To control the appearance of the pager row (including its background color, font color, and position), use the PagerStyle property. DetailsView控件还允许您为页导航行定义自定义模板。The DetailsView control also allows you to define a custom template for the pager row. 有关创建自定义页导航行模板的详细信息, PagerTemplate请参阅。For more information on creating a custom pager row template, see PagerTemplate.

DetailsView控件提供若干事件, 可用于在进行分页时执行自定义操作。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 在单击某一页导航按钮时,但在 DetailsView 控件处理分页操作之后发生。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 在单击某一页导航按钮时,但在 DetailsView 控件处理分页操作之前发生。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.

的值AllowPaging存储在视图状态中。The value of AllowPaging is stored in view state.

适用于

另请参阅