GridView.AllowPaging 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否启用分页功能。
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;否则为 false。 默认值为 false。
示例
以下示例演示如何使用 AllowPaging 属性以声明方式在控件中 GridView 启用分页功能。
<%@ 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>GridView AllowPaging Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView AllowPaging Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
allowpaging="true"
runat="server">
<pagersettings mode="Numeric"
position="Bottom"
pagebuttoncount="10"/>
<pagerstyle backcolor="LightBlue"
height="30px"
verticalalign="Bottom"
horizontalalign="Center"/>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</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>GridView AllowPaging Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView AllowPaging Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
allowpaging="true"
runat="server">
<pagersettings mode="Numeric"
position="Bottom"
pagebuttoncount="10"/>
<pagerstyle backcolor="LightBlue"
height="30px"
verticalalign="Bottom"
horizontalalign="Center"/>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
注解
控件可以自动将记录分解为页面, GridView 而不是同时显示数据源中的所有记录。 如果数据源支持分页功能,控件 GridView 可以利用该功能并提供内置分页功能。 分页功能可与支持 System.Collections.ICollection 接口或支持分页功能的数据源对象一起使用。
若要启用分页功能,请将 AllowPaging 属性设置为 true。 默认情况下,控件 GridView 一次在页面上显示 10 条记录。 可以通过设置 PageSize 属性来更改页面上显示的记录数。 若要确定显示数据源内容所需的总页数,请使用 PageCount 该属性。 可以使用该 PageIndex 属性确定当前显示页面的索引。
启用分页后,控件中 GridView 会自动显示名为寻呼行的其他行。 寻呼行包含允许用户导航到其他页面的控件。 可以控制寻呼行 (的设置,例如寻呼模式、一次要显示的页链接数,以及使用 PagerSettings 属性) 寻呼控件的文本标签。 可以通过设置 Position 属性,在顶部、底部或控件的顶部和底部显示寻呼行。 还可以通过设置 Mode 属性从四种内置寻呼器显示模式之一中进行选择。 下表介绍了内置显示模式。
| “模式” | 说明 |
|---|---|
PagerButton.NextPrevious |
由上一个和下一个按钮组成的一组分页控件。 |
PagerButton.NextPreviousFirstLast |
由上一个、下一个、第一个和最后一个按钮组成的一组分页控件。 |
PagerButton.Numeric |
一组由用于直接访问页的带编号的链接按钮组成的分页控件。 这是默认模式。 |
PagerButton.NumericFirstLast |
一组分页控件,其中包含编号和第一个和最后一个链接按钮。 |
若要控制寻呼行的外观, (包括其背景色、字体颜色和位置) ,请使用该 PagerStyle 属性。
备注
当数据源仅包含一页记录时,控件 GridView 会自动隐藏寻呼行。
该 GridView 控件还允许为寻呼行定义自定义模板。 有关创建自定义寻呼行模板的详细信息,请参阅 PagerTemplate。
控件 GridView 提供了多个事件,可用于执行分页时执行自定义操作。 下表列出了可用的事件。
| 事件 | 说明 |
|---|---|
| PageIndexChanged | 在单击某一页导航按钮时,但在 GridView 控件处理分页操作之后发生。 当用户导航到控件中的其他页面后,通常需要执行任务时,通常会使用此事件。 |
| PageIndexChanging | 在单击某一页导航按钮时,但在 GridView 控件处理分页操作之前发生。 此事件通常用于取消分页操作。 |